github.com/abemedia/appcast@v0.4.0/integrations/apk/acceptance_test.go (about) 1 //go:build acceptance 2 3 package apk_test 4 5 import ( 6 "context" 7 "testing" 8 9 "github.com/abemedia/appcast/integrations/apk" 10 "github.com/abemedia/appcast/internal/emulator" 11 "github.com/abemedia/appcast/pkg/crypto/rsa" 12 source "github.com/abemedia/appcast/source/file" 13 target "github.com/abemedia/appcast/target/file" 14 ) 15 16 func TestAcceptance(t *testing.T) { 17 distros := []struct { 18 name string 19 image string 20 }{ 21 {"Alpine 3", "alpine:3"}, 22 } 23 24 tests := []struct { 25 name string 26 version string 27 }{ 28 {"Install", "v1.0.0"}, 29 {"Update", "v2.0.0"}, 30 } 31 32 for _, distro := range distros { 33 t.Run(distro.name, func(t *testing.T) { 34 dir := t.TempDir() 35 rsaKey, _ := rsa.NewPrivateKey() 36 src, _ := source.New(source.Config{Path: "../../testdata"}) 37 tgt, _ := target.New(target.Config{Path: dir}) 38 url := emulator.FileServer(t, dir) 39 c := emulator.Image(t, distro.image) 40 41 for i, test := range tests { 42 t.Run(test.name, func(t *testing.T) { 43 config := &apk.Config{Source: src, Target: tgt, Version: test.version, RSAKey: rsaKey, KeyName: "test@example.com.rsa.pub"} 44 if err := apk.Build(context.Background(), config); err != nil { 45 t.Fatal(err) 46 } 47 48 if i == 0 { 49 c.Exec(t, "echo '"+url+"' >> /etc/apk/repositories") 50 c.Exec(t, "apk add --no-cache wget") 51 c.Exec(t, "wget -q -O /etc/apk/keys/"+config.KeyName+" "+url+"/"+config.KeyName) 52 c.Exec(t, "apk add --no-cache appcast-test") 53 } else { 54 c.Exec(t, "apk upgrade --no-cache appcast-test") 55 } 56 57 if v := c.Exec(t, "appcast-test"); v != test.version { 58 t.Fatalf("expected version %q got %q", test.version, v) 59 } 60 }) 61 62 if t.Failed() { 63 t.FailNow() 64 } 65 } 66 }) 67 } 68 }