|
5 | 5 | package test
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "context" |
8 | 9 | "fmt"
|
9 |
| - "os" |
10 | 10 | "path/filepath"
|
11 | 11 | "testing"
|
12 | 12 |
|
13 | 13 | "github.com/stretchr/testify/require"
|
14 |
| - "github.com/stretchr/testify/suite" |
15 |
| -) |
16 |
| - |
17 |
| -type FlavorSuite struct { |
18 |
| - suite.Suite |
19 |
| - *require.Assertions |
20 |
| -} |
21 | 14 |
|
22 |
| -var ( |
23 |
| - flavorExample = filepath.Join("examples", "package-flavors") |
24 |
| - flavorTest = filepath.Join("src", "test", "packages", "10-package-flavors") |
25 |
| - flavorExamplePath string |
26 |
| - flavorTestAMDPath = filepath.Join("build", "zarf-package-test-package-flavors-amd64.tar.zst") |
27 |
| - flavorTestARMPath = filepath.Join("build", "zarf-package-test-package-flavors-arm64.tar.zst") |
| 15 | + layout2 "github.com/zarf-dev/zarf/src/internal/packager2/layout" |
28 | 16 | )
|
29 | 17 |
|
30 |
| -func (suite *FlavorSuite) SetupSuite() { |
31 |
| - suite.Assertions = require.New(suite.T()) |
32 |
| - |
33 |
| - // Setup the example package path after e2e has been initialized |
34 |
| - flavorExamplePath = filepath.Join("build", fmt.Sprintf("zarf-package-package-flavors-%s-1.0.0.tar.zst", e2e.Arch)) |
35 |
| -} |
36 |
| - |
37 |
| -func (suite *FlavorSuite) TearDownSuite() { |
38 |
| - err := os.RemoveAll(flavorExamplePath) |
39 |
| - suite.NoError(err) |
40 |
| - err = os.RemoveAll(flavorTestAMDPath) |
41 |
| - suite.NoError(err) |
42 |
| - err = os.RemoveAll(flavorTestARMPath) |
43 |
| - suite.NoError(err) |
44 |
| -} |
45 |
| - |
46 |
| -func (suite *FlavorSuite) Test_0_FlavorExample() { |
47 |
| - suite.T().Log("E2E: Package Flavor Example") |
48 |
| - |
49 |
| - _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", flavorExample, "-o", "build", "--flavor", "oracle-cookie-crunch", "--no-color", "--confirm") |
50 |
| - suite.NoError(err) |
51 |
| - |
52 |
| - // Ensure that the oracle image is included |
53 |
| - suite.Contains(stdErr, `oraclelinux:9-slim`) |
54 |
| - |
55 |
| - // Ensure that the common pod was included |
56 |
| - suite.Contains(stdErr, `description: The pod that runs the specified flavor of Enterprise Linux`) |
57 |
| - |
58 |
| - // Ensure that the other flavors are not included |
59 |
| - suite.NotContains(stdErr, `rockylinux:9-minimal`) |
60 |
| - suite.NotContains(stdErr, `almalinux:9-minimal`) |
61 |
| - suite.NotContains(stdErr, `opensuse/leap:15`) |
62 |
| -} |
63 |
| - |
64 |
| -func (suite *FlavorSuite) Test_1_FlavorArchFiltering() { |
65 |
| - suite.T().Log("E2E: Package Flavor + Arch Filtering") |
66 |
| - |
67 |
| - _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", flavorTest, "-o", "build", "--flavor", "vanilla", "-a", "amd64", "--no-color", "--confirm") |
68 |
| - suite.NoError(err) |
69 |
| - |
70 |
| - // Ensure that the initial filter was applied |
71 |
| - suite.Contains(stdErr, ` |
72 |
| -- name: combined |
73 |
| - description: vanilla-amd`) |
74 |
| - |
75 |
| - // Ensure that the import filter was applied |
76 |
| - suite.Contains(stdErr, ` |
77 |
| -- name: via-import |
78 |
| - description: vanilla-amd`) |
79 |
| - |
80 |
| - // Ensure that the other flavors / architectures are not included |
81 |
| - suite.NotContains(stdErr, `vanilla-arm`) |
82 |
| - suite.NotContains(stdErr, `chocolate-amd`) |
83 |
| - suite.NotContains(stdErr, `chocolate-arm`) |
84 |
| - |
85 |
| - _, stdErr, err = e2e.Zarf(suite.T(), "package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "amd64", "--no-color", "--confirm") |
86 |
| - suite.NoError(err) |
87 |
| - |
88 |
| - // Ensure that the initial filter was applied |
89 |
| - suite.Contains(stdErr, ` |
90 |
| -- name: combined |
91 |
| - description: chocolate-amd`) |
92 |
| - |
93 |
| - // Ensure that the import filter was applied |
94 |
| - suite.Contains(stdErr, ` |
95 |
| -- name: via-import |
96 |
| - description: chocolate-amd`) |
97 |
| - |
98 |
| - // Ensure that the other flavors / architectures are not included |
99 |
| - suite.NotContains(stdErr, `vanilla-arm`) |
100 |
| - suite.NotContains(stdErr, `vanilla-amd`) |
101 |
| - suite.NotContains(stdErr, `chocolate-arm`) |
102 |
| - |
103 |
| - _, stdErr, err = e2e.Zarf(suite.T(), "package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "arm64", "--no-color", "--confirm") |
104 |
| - suite.NoError(err) |
105 |
| - |
106 |
| - // Ensure that the initial filter was applied |
107 |
| - suite.Contains(stdErr, ` |
108 |
| -- name: combined |
109 |
| - description: chocolate-arm`) |
110 |
| - |
111 |
| - // Ensure that the import filter was applied |
112 |
| - suite.Contains(stdErr, ` |
113 |
| -- name: via-import |
114 |
| - description: chocolate-arm`) |
115 |
| - |
116 |
| - // Ensure that the other flavors / architectures are not included |
117 |
| - suite.NotContains(stdErr, `vanilla-arm`) |
118 |
| - suite.NotContains(stdErr, `vanilla-amd`) |
119 |
| - suite.NotContains(stdErr, `chocolate-amd`) |
| 18 | +func TestFlavorExample(t *testing.T) { |
| 19 | + t.Parallel() |
| 20 | + |
| 21 | + tmpDir := t.TempDir() |
| 22 | + flavorExample := filepath.Join("examples", "package-flavors") |
| 23 | + _, _, err := e2e.Zarf(t, "package", "create", flavorExample, "-o", tmpDir, "--flavor", "oracle-cookie-crunch", "--no-color", "--confirm") |
| 24 | + require.NoError(t, err) |
| 25 | + |
| 26 | + tarPath := filepath.Join(tmpDir, fmt.Sprintf("zarf-package-package-flavors-%s-1.0.0.tar.zst", e2e.Arch)) |
| 27 | + pkgLayout, err := layout2.LoadFromTar(context.Background(), tarPath, layout2.PackageLayoutOptions{}) |
| 28 | + require.NoError(t, err) |
| 29 | + pkgLayout.Pkg.Metadata.Description = "The pod that runs the specified flavor of Enterprise Linux" |
| 30 | + imgs := []string{} |
| 31 | + for _, comp := range pkgLayout.Pkg.Components { |
| 32 | + imgs = append(imgs, comp.Images...) |
| 33 | + } |
| 34 | + require.ElementsMatch(t, imgs, []string{"oraclelinux:9-slim"}) |
120 | 35 | }
|
121 | 36 |
|
122 |
| -func TestFlavorSuite(t *testing.T) { |
123 |
| - suite.Run(t, new(FlavorSuite)) |
| 37 | +func TestFlavorArchFiltering(t *testing.T) { |
| 38 | + t.Parallel() |
| 39 | + |
| 40 | + tests := []struct { |
| 41 | + arch string |
| 42 | + flavor string |
| 43 | + expectedIDs []string |
| 44 | + }{ |
| 45 | + { |
| 46 | + arch: "amd64", |
| 47 | + flavor: "vanilla", |
| 48 | + expectedIDs: []string{"combined-vanilla-amd", "via-import-vanilla-amd"}, |
| 49 | + }, |
| 50 | + { |
| 51 | + arch: "amd64", |
| 52 | + flavor: "chocolate", |
| 53 | + expectedIDs: []string{"combined-chocolate-amd", "via-import-chocolate-amd"}, |
| 54 | + }, |
| 55 | + { |
| 56 | + arch: "arm64", |
| 57 | + flavor: "chocolate", |
| 58 | + expectedIDs: []string{"combined-chocolate-arm", "via-import-chocolate-arm"}, |
| 59 | + }, |
| 60 | + } |
| 61 | + for _, tt := range tests { |
| 62 | + t.Run(tt.arch+"-"+tt.flavor, func(t *testing.T) { |
| 63 | + t.Parallel() |
| 64 | + |
| 65 | + tmpDir := t.TempDir() |
| 66 | + flavorTest := filepath.Join("src", "test", "packages", "10-package-flavors") |
| 67 | + _, _, err := e2e.Zarf(t, "package", "create", flavorTest, "-o", tmpDir, "--flavor", tt.flavor, "-a", tt.arch, "--no-color", "--confirm") |
| 68 | + require.NoError(t, err) |
| 69 | + |
| 70 | + tarPath := filepath.Join(tmpDir, fmt.Sprintf("zarf-package-test-package-flavors-%s.tar.zst", tt.arch)) |
| 71 | + pkgLayout, err := layout2.LoadFromTar(context.Background(), tarPath, layout2.PackageLayoutOptions{}) |
| 72 | + require.NoError(t, err) |
| 73 | + compIDs := []string{} |
| 74 | + for _, comp := range pkgLayout.Pkg.Components { |
| 75 | + compIDs = append(compIDs, comp.Name+"-"+comp.Description) |
| 76 | + } |
| 77 | + require.ElementsMatch(t, compIDs, tt.expectedIDs) |
| 78 | + }) |
| 79 | + } |
124 | 80 | }
|
0 commit comments