github.com/abemedia/appcast@v0.4.0/integrations/apt/acceptance_test.go (about)

     1  //go:build acceptance
     2  
     3  package apt_test
     4  
     5  import (
     6  	"context"
     7  	"testing"
     8  
     9  	"github.com/abemedia/appcast/integrations/apt"
    10  	"github.com/abemedia/appcast/internal/emulator"
    11  	"github.com/abemedia/appcast/pkg/crypto/pgp"
    12  	source "github.com/abemedia/appcast/source/file"
    13  	ftarget "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  		{"Debian 12", "debian:12"},
    22  		{"Debian 11", "debian:11"},
    23  		{"Ubuntu 22.04", "ubuntu:jammy"},
    24  		{"Ubuntu 20.04", "ubuntu:focal"},
    25  	}
    26  
    27  	tests := []struct {
    28  		name    string
    29  		version string
    30  	}{
    31  		{"Install", "v1.0.0"},
    32  		{"Update", "v2.0.0"},
    33  	}
    34  
    35  	for _, distro := range distros {
    36  		t.Run(distro.name, func(t *testing.T) {
    37  			dir := t.TempDir()
    38  			pgpKey, _ := pgp.NewPrivateKey("test", "test@example.com")
    39  			key, _ := pgp.MarshalPublicKey(pgp.Public(pgpKey))
    40  			src, _ := source.New(source.Config{Path: "../../testdata"})
    41  			tgt, _ := ftarget.New(ftarget.Config{Path: dir})
    42  			url := emulator.FileServer(t, dir)
    43  			c := emulator.Build(t, `
    44  				FROM `+distro.image+`
    45  				ENV DEBIAN_FRONTEND=noninteractive
    46  				RUN apt-get update && apt-get install -y --no-install-recommends gpg apt-utils
    47  				ENTRYPOINT ["tail", "-f", "/dev/null"]
    48  			`)
    49  
    50  			c.CopyToContainer(context.Background(), key, "appcast-test.asc", 0o644)
    51  			c.Exec(t, "gpg --dearmor --yes --output /usr/share/keyrings/appcast-test.gpg < appcast-test.asc")
    52  			c.Exec(t, "echo 'deb [signed-by=/usr/share/keyrings/appcast-test.gpg] "+url+" stable main' > /etc/apt/sources.list.d/appcast-test.list")
    53  
    54  			for i, test := range tests {
    55  				t.Run(test.name, func(t *testing.T) {
    56  					config := &apt.Config{Source: src, Target: tgt, Version: test.version, PGPKey: pgpKey}
    57  					if err := apt.Build(context.Background(), config); err != nil {
    58  						t.Fatal(err)
    59  					}
    60  
    61  					c.Exec(t, "apt-get update -q")
    62  
    63  					if i == 0 {
    64  						c.Exec(t, "apt-get install -yq --no-install-recommends appcast-test")
    65  					} else {
    66  						c.Exec(t, "apt-get upgrade -yq")
    67  					}
    68  
    69  					if v := c.Exec(t, "appcast-test"); v != test.version {
    70  						t.Fatalf("expected version %q got %q", test, v)
    71  					}
    72  				})
    73  
    74  				if t.Failed() {
    75  					t.FailNow()
    76  				}
    77  			}
    78  		})
    79  	}
    80  }