From ee9406513c879062914cd0af4d45c4fd136bb6c5 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sat, 9 Jan 2021 10:15:56 -0600 Subject: [PATCH] Added a new test for fun to compare vs unsquashfs --- squash_test.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/squash_test.go b/squash_test.go index 34f8339..fd105af 100644 --- a/squash_test.go +++ b/squash_test.go @@ -5,7 +5,10 @@ import ( "io" "net/http" "os" + "os/exec" + "strconv" "testing" + "time" goappimage "github.com/CalebQ42/GoAppImage" ) @@ -68,7 +71,8 @@ func TestAppImage(t *testing.T) { if err != nil { t.Fatal(err) } - os.RemoveAll(wd + "testing/firefox") + start := time.Now() + // os.RemoveAll(wd + "testing/firefox") errs := rdr.ExtractTo(wd + "/testing/firefox") if len(errs) > 0 { t.Fatal(errs) @@ -77,9 +81,38 @@ func TestAppImage(t *testing.T) { // root, _ := rdr.GetRootFolder() // errs := root.ExtractWithOptions(wd+"/testing/"+appImageName+".d", true, os.ModePerm, true) // t.Fatal(errs) + fmt.Println(time.Since(start)) t.Fatal("No problemo!") } +func TestUnsquashfs(t *testing.T) { + t.Parallel() + wd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + aiFil, err := os.Open(wd + "/testing/" + appImageName) + if os.IsNotExist(err) { + downloadTestAppImage(t, wd+"/testing") + aiFil, err = os.Open(wd + "/testing/" + appImageName) + if err != nil { + t.Fatal(err) + } + } else if err != nil { + t.Fatal(err) + } + ai := goappimage.NewAppImage(wd + "/testing/" + appImageName) + fmt.Println("Command:", "unsquashfs", "-d", wd+"/testing/unsquashFirefox", "-o", strconv.Itoa(int(ai.Offset)), aiFil.Name()) + cmd := exec.Command("unsquashfs", "-d", wd+"/testing/unsquashFirefox", "-o", strconv.Itoa(int(ai.Offset)), aiFil.Name()) + start := time.Now() + err = cmd.Run() + if err != nil { + t.Fatal(err) + } + fmt.Println(time.Since(start)) + t.Fatal("HI") +} + func downloadTestAppImage(t *testing.T, dir string) { //seems to time out on slow connections. Might fix that at some point... or not. It's just a test... os.Mkdir(dir, os.ModePerm)