Skip to content

Commit 27db1e6

Browse files
committed
Refactor compose e2e test to not depend on CLI output
Signed-off-by: Philip Laine <[email protected]>
1 parent 72769a9 commit 27db1e6

File tree

1 file changed

+88
-107
lines changed

1 file changed

+88
-107
lines changed

src/test/e2e/09_component_compose_test.go

+88-107
Original file line numberDiff line numberDiff line change
@@ -5,97 +5,105 @@
55
package test
66

77
import (
8+
"context"
89
"fmt"
9-
"os"
1010
"path/filepath"
1111
"testing"
1212

13+
goyaml "github.com/goccy/go-yaml"
1314
"github.com/stretchr/testify/require"
14-
"github.com/stretchr/testify/suite"
15-
)
16-
17-
type CompositionSuite struct {
18-
suite.Suite
19-
*require.Assertions
20-
}
2115

22-
var (
23-
composeExample = filepath.Join("examples", "composable-packages")
24-
composeExamplePath string
25-
composeTest = filepath.Join("src", "test", "packages", "09-composable-packages")
26-
composeTestPath string
27-
composeTestBadLocalOS = filepath.Join("src", "test", "packages", "09-composable-packages", "bad-local-os")
16+
layout2 "github.com/zarf-dev/zarf/src/internal/packager2/layout"
2817
)
2918

30-
func (suite *CompositionSuite) SetupSuite() {
31-
suite.Assertions = require.New(suite.T())
32-
33-
// Setup the package paths after e2e has been initialized
34-
composeExamplePath = filepath.Join("build", fmt.Sprintf("zarf-package-composable-packages-%s.tar.zst", e2e.Arch))
35-
composeTestPath = filepath.Join("build", fmt.Sprintf("zarf-package-test-compose-package-%s.tar.zst", e2e.Arch))
36-
}
19+
func TestComposabilityExample(t *testing.T) {
20+
t.Parallel()
3721

38-
func (suite *CompositionSuite) TearDownSuite() {
39-
err := os.RemoveAll(composeExamplePath)
40-
suite.NoError(err)
41-
err = os.RemoveAll(composeTestPath)
42-
suite.NoError(err)
43-
}
22+
tmpDir := t.TempDir()
23+
composeExample := filepath.Join("examples", "composable-packages")
24+
_, _, err := e2e.Zarf(t, "package", "create", composeExample, "-o", tmpDir, "--no-color", "--confirm", "--zarf-cache", tmpDir)
25+
require.NoError(t, err)
4426

45-
func (suite *CompositionSuite) Test_0_ComposabilityExample() {
46-
suite.T().Log("E2E: Package Compose Example")
27+
tarPath := filepath.Join(tmpDir, fmt.Sprintf("zarf-package-composable-packages-%s.tar.zst", e2e.Arch))
28+
pkgLayout, err := layout2.LoadFromTar(context.Background(), tarPath, layout2.PackageLayoutOptions{})
29+
require.NoError(t, err)
4730

48-
_, stdErr, err := e2e.Zarf(suite.T(), "package", "create", composeExample, "-o", "build", "--no-color", "--confirm")
49-
suite.NoError(err)
31+
require.Len(t, pkgLayout.Pkg.Components, 2)
32+
b, err := goyaml.Marshal(pkgLayout.Pkg.Components)
33+
require.NoError(t, err)
5034

51-
// Ensure that common names merge
52-
manifests := e2e.NormalizeYAMLFilenames(`
35+
expectedYaml := fmt.Sprintf(`- name: local-games-path
36+
description: Example of a local composed package with a unique description for this component
37+
required: true
5338
manifests:
5439
- name: multi-games
5540
namespace: dos-games
5641
files:
5742
- ../dos-games/manifests/deployment.yaml
5843
- ../dos-games/manifests/service.yaml
59-
- quake-service.yaml`)
60-
suite.Contains(stdErr, manifests)
61-
62-
// Ensure that the action was appended
63-
suite.Contains(stdErr, `
44+
- quake-service.yaml
45+
images:
46+
- ghcr.io/zarf-dev/doom-game:0.0.1
47+
- name: oci-games-url
48+
manifests:
49+
- name: multi-games
50+
namespace: dos-games
51+
files:
52+
- ../../../../../../..%s/oci/dirs/9ece174e362633b637e3c6b554b70f7d009d0a27107bee822336fdf2ce9a9def/manifests/multi-games-0.yaml
53+
- ../../../../../../..%s/oci/dirs/9ece174e362633b637e3c6b554b70f7d009d0a27107bee822336fdf2ce9a9def/manifests/multi-games-1.yaml
54+
images:
6455
- ghcr.io/zarf-dev/doom-game:0.0.1
6556
actions:
6657
onDeploy:
6758
before:
68-
- cmd: ./zarf tools kubectl get -n dos-games deployment -o jsonpath={.items[0].metadata.creationTimestamp}`)
59+
- cmd: ./zarf tools kubectl get -n dos-games deployment -o jsonpath={.items[0].metadata.creationTimestamp}
60+
after:
61+
- wait:
62+
cluster:
63+
kind: deployment
64+
name: game
65+
namespace: dos-games
66+
condition: available
67+
`, tmpDir, tmpDir)
68+
require.Equal(t, expectedYaml, string(b))
6969
}
7070

71-
func (suite *CompositionSuite) Test_1_FullComposability() {
72-
suite.T().Log("E2E: Full Package Compose")
71+
func TestFullComposability(t *testing.T) {
72+
t.Parallel()
73+
74+
tmpDir := t.TempDir()
75+
composeTest := filepath.Join("src", "test", "packages", "09-composable-packages")
76+
_, _, err := e2e.Zarf(t, "package", "create", composeTest, "-o", tmpDir, "--no-color", "--confirm")
77+
require.NoError(t, err)
7378

74-
_, stdErr, err := e2e.Zarf(suite.T(), "package", "create", composeTest, "-o", "build", "--no-color", "--confirm")
75-
suite.NoError(err)
79+
tarPath := filepath.Join(tmpDir, fmt.Sprintf("zarf-package-test-compose-package-%s-0.0.1.tar.zst", e2e.Arch))
80+
pkgLayout, err := layout2.LoadFromTar(context.Background(), tarPath, layout2.PackageLayoutOptions{})
81+
require.NoError(t, err)
7682

77-
// Ensure that names merge and that composition is added appropriately
83+
require.Len(t, pkgLayout.Pkg.Components, 1)
84+
b, err := goyaml.Marshal(pkgLayout.Pkg.Components)
85+
require.NoError(t, err)
7886

79-
// Check metadata
80-
suite.Contains(stdErr, `
81-
- name: test-compose-package
87+
expectedYaml := `- name: test-compose-package
8288
description: A contrived example for podinfo using many Zarf primitives for compose testing
8389
required: true
8490
only:
8591
localOS: linux
86-
`)
87-
88-
// Check files
89-
suite.Contains(stdErr, e2e.NormalizeYAMLFilenames(`
90-
files:
91-
- source: files/coffee-ipsum.txt
92-
target: coffee-ipsum.txt
93-
- source: files/coffee-ipsum.txt
94-
target: coffee-ipsum.txt
95-
`))
96-
97-
// Check charts
98-
suite.Contains(stdErr, e2e.NormalizeYAMLFilenames(`
92+
manifests:
93+
- name: connect-service
94+
namespace: podinfo-override
95+
files:
96+
- files/service.yaml
97+
- files/service.yaml
98+
kustomizations:
99+
- files
100+
- files
101+
- name: connect-service-two
102+
namespace: podinfo-compose-two
103+
files:
104+
- files/service.yaml
105+
kustomizations:
106+
- files
99107
charts:
100108
- name: podinfo-compose
101109
version: 6.4.0
@@ -112,39 +120,6 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
112120
releaseName: podinfo-compose-two
113121
valuesFiles:
114122
- files/test-values.yaml
115-
`))
116-
117-
// Check manifests
118-
suite.Contains(stdErr, e2e.NormalizeYAMLFilenames(`
119-
manifests:
120-
- name: connect-service
121-
namespace: podinfo-override
122-
files:
123-
- files/service.yaml
124-
- files/service.yaml
125-
kustomizations:
126-
- files
127-
- files
128-
- name: connect-service-two
129-
namespace: podinfo-compose-two
130-
files:
131-
- files/service.yaml
132-
kustomizations:
133-
- files
134-
`))
135-
136-
// Check images + repos
137-
suite.Contains(stdErr, `
138-
images:
139-
- ghcr.io/stefanprodan/podinfo:6.4.0
140-
- ghcr.io/stefanprodan/podinfo:6.4.1
141-
repos:
142-
- https://github.com/zarf-dev/zarf-public-test.git
143-
- https://github.com/zarf-dev/zarf-public-test.git@refs/heads/dragons
144-
`)
145-
146-
// Check dataInjections
147-
suite.Contains(stdErr, `
148123
dataInjections:
149124
- source: files
150125
target:
@@ -158,10 +133,17 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
158133
selector: app.kubernetes.io/name=podinfo-compose
159134
container: podinfo
160135
path: /home/app/service.yaml
161-
`)
162-
163-
// Check actions
164-
suite.Contains(stdErr, `
136+
files:
137+
- source: files/coffee-ipsum.txt
138+
target: coffee-ipsum.txt
139+
- source: files/coffee-ipsum.txt
140+
target: coffee-ipsum.txt
141+
images:
142+
- ghcr.io/stefanprodan/podinfo:6.4.0
143+
- ghcr.io/stefanprodan/podinfo:6.4.1
144+
repos:
145+
- https://github.com/zarf-dev/zarf-public-test.git
146+
- https://github.com/zarf-dev/zarf-public-test.git@refs/heads/dragons
165147
actions:
166148
onCreate:
167149
before:
@@ -177,17 +159,16 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
177159
kind: deployment
178160
name: podinfo-compose-two
179161
namespace: podinfo-compose-two
180-
condition: available`)
162+
condition: available
163+
`
164+
require.Equal(t, expectedYaml, string(b))
181165
}
182166

183-
func (suite *CompositionSuite) Test_2_ComposabilityBadLocalOS() {
184-
suite.T().Log("E2E: Package Compose Example")
185-
186-
_, stdErr, err := e2e.Zarf(suite.T(), "package", "create", composeTestBadLocalOS, "-o", "build", "--no-color", "--confirm")
187-
suite.Error(err)
188-
suite.Contains(e2e.StripMessageFormatting(stdErr), "\"only.localOS\" \"linux\" cannot be redefined as \"windows\" during compose")
189-
}
167+
func TestComposabilityBadLocalOS(t *testing.T) {
168+
t.Parallel()
190169

191-
func TestCompositionSuite(t *testing.T) {
192-
suite.Run(t, new(CompositionSuite))
170+
composeTestBadLocalOS := filepath.Join("src", "test", "packages", "09-composable-packages", "bad-local-os")
171+
_, stdErr, err := e2e.Zarf(t, "package", "create", composeTestBadLocalOS, "-o", "build", "--no-color", "--confirm")
172+
require.Error(t, err)
173+
require.Contains(t, e2e.StripMessageFormatting(stdErr), "\"only.localOS\" \"linux\" cannot be redefined as \"windows\" during compose")
193174
}

0 commit comments

Comments
 (0)