Improved testing

This commit is contained in:
Caleb Gardner
2021-09-26 19:10:43 -05:00
parent 0402b0a2ee
commit 64055a8a63
+43 -3
View File
@@ -14,9 +14,10 @@ import (
)
const (
downloadURL = "https://github.com/srevinsaju/Firefox-Appimage/releases/download/firefox-v84.0.r20201221152838/firefox-84.0.r20201221152838-x86_64.AppImage"
appImageURL = "https://github.com/srevinsaju/Firefox-Appimage/releases/download/firefox-v84.0.r20201221152838/firefox-84.0.r20201221152838-x86_64.AppImage"
appImageName = "firefox-84.0.r20201221152838-x86_64.AppImage"
squashfsName = "balenaEtcher-1.5.113-x64.AppImage.sfs"
squashfsURL = "https://darkstorm.tech/LinuxPATest.sfs"
squashfsName = "LinuxPATest.sfs"
)
func TestSquashfs(t *testing.T) {
@@ -25,6 +26,13 @@ func TestSquashfs(t *testing.T) {
t.Fatal(err)
}
squashFil, err := os.Open(wd + "/testing/" + squashfsName)
if os.IsNotExist(err) {
err = downloadTestSquash(wd + "/testing")
if err != nil {
t.Fatal(err)
}
squashFil, err = os.Open(wd + "/testing/" + squashfsName)
}
if err != nil {
t.Fatal(err)
}
@@ -32,6 +40,12 @@ func TestSquashfs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
op := DefaultOptions()
op.Verbose = true
err = rdr.ExtractWithOptions(wd+"/testing/"+squashfsName+".d", op)
if err != nil {
t.Fatal(err)
}
fmt.Println("stuff", rdr.super.CompressionType)
// fil := rdr.GetFileAtPath("*.desktop")
// if fil == nil {
@@ -171,7 +185,7 @@ func downloadTestAppImage(dir string) error {
return nil
},
}
resp, err := check.Get(downloadURL)
resp, err := check.Get(appImageURL)
if err != nil {
return err
}
@@ -183,6 +197,32 @@ func downloadTestAppImage(dir string) error {
return nil
}
func downloadTestSquash(dir string) error {
//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)
sfs, err := os.Create(dir + "/" + squashfsName)
if err != nil {
return err
}
defer sfs.Close()
check := http.Client{
CheckRedirect: func(r *http.Request, _ []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}
resp, err := check.Get(squashfsURL)
if err != nil {
return err
}
defer resp.Body.Close()
_, err = io.Copy(sfs, resp.Body)
if err != nil {
return err
}
return nil
}
func TestCreateSquashFromAppImage(t *testing.T) {
wd, err := os.Getwd()
if err != nil {