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

     1  //go:build acceptance
     2  
     3  package yum_test
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  	"testing"
     9  
    10  	"github.com/abemedia/appcast/integrations/yum"
    11  	"github.com/abemedia/appcast/internal/emulator"
    12  	"github.com/abemedia/appcast/pkg/crypto/pgp"
    13  	source "github.com/abemedia/appcast/source/file"
    14  	target "github.com/abemedia/appcast/target/file"
    15  )
    16  
    17  const conf = `[appcast-test]
    18  name=appcast-test
    19  baseurl=%s
    20  enabled=1
    21  gpgcheck=0
    22  repo_gpgcheck=1
    23  gpgkey=%s/repodata/repomd.xml.key`
    24  
    25  func TestAcceptance(t *testing.T) {
    26  	distros := []struct {
    27  		name  string
    28  		image string
    29  		pkg   string
    30  	}{
    31  		{"RHEL 9", "registry.access.redhat.com/ubi9/ubi:latest", "dnf"},
    32  		{"RHEL 8", "registry.access.redhat.com/ubi8/ubi:latest", "dnf"},
    33  		{"Fedora 39", "fedora:39", "dnf"},
    34  		{"Fedora 38", "fedora:38", "dnf"},
    35  		{"openSUSE Leap 15", "opensuse/leap:15", "zypper"},
    36  	}
    37  
    38  	tests := []struct {
    39  		name    string
    40  		version string
    41  	}{
    42  		{"Install", "v1.0.0"},
    43  		{"Update", "v2.0.0"},
    44  	}
    45  
    46  	for _, distro := range distros {
    47  		t.Run(distro.name, func(t *testing.T) {
    48  			dir := t.TempDir()
    49  			pgpKey, _ := pgp.NewPrivateKey("test", "test@example.com")
    50  			src, _ := source.New(source.Config{Path: "../../testdata"})
    51  			tgt, _ := target.New(target.Config{Path: dir})
    52  			url := emulator.FileServer(t, dir)
    53  			c := emulator.Image(t, distro.image)
    54  
    55  			for i, test := range tests {
    56  				t.Run(test.name, func(t *testing.T) {
    57  					config := &yum.Config{Source: src, Target: tgt, Version: test.version, PGPKey: pgpKey}
    58  					if err := yum.Build(context.Background(), config); err != nil {
    59  						t.Fatal(err)
    60  					}
    61  
    62  					switch distro.pkg {
    63  					case "dnf":
    64  						if i == 0 {
    65  							c.Exec(t, "echo '"+fmt.Sprintf(conf, url, url)+"' > /etc/yum.repos.d/appcast-test.repo")
    66  							c.Exec(t, "dnf install -yq appcast-test")
    67  						} else {
    68  							c.Exec(t, "dnf clean expire-cache")
    69  							c.Exec(t, "dnf update -yq appcast-test")
    70  						}
    71  					case "zypper":
    72  						if i == 0 {
    73  							c.Exec(t, "zypper addrepo --refresh "+url+" appcast-test")
    74  							c.Exec(t, "zypper --gpg-auto-import-keys refresh")
    75  							c.Exec(t, "zypper --non-interactive install appcast-test")
    76  						} else {
    77  							c.Exec(t, "zypper refresh")
    78  							c.Exec(t, "zypper --non-interactive update appcast-test")
    79  						}
    80  					}
    81  
    82  					if v := c.Exec(t, "appcast-test"); v != test.version {
    83  						t.Fatalf("expected version %q got %q", test.version, v)
    84  					}
    85  				})
    86  
    87  				if t.Failed() {
    88  					t.FailNow()
    89  				}
    90  			}
    91  		})
    92  	}
    93  }