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
+ goyaml "github.com/goccy/go-yaml"
13
14
"github.com/stretchr/testify/require"
14
- "github.com/stretchr/testify/suite"
15
- )
16
-
17
- type CompositionSuite struct {
18
- suite.Suite
19
- * require.Assertions
20
- }
21
15
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"
28
17
)
29
18
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 ()
37
21
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 )
44
26
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 )
47
30
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 )
50
34
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
53
38
manifests:
54
39
- name: multi-games
55
40
namespace: dos-games
56
41
files:
57
42
- ../dos-games/manifests/deployment.yaml
58
43
- ../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:
64
55
- ghcr.io/zarf-dev/doom-game:0.0.1
65
56
actions:
66
57
onDeploy:
67
58
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 ))
69
69
}
70
70
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 )
73
78
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 )
76
82
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 )
78
86
79
- // Check metadata
80
- suite .Contains (stdErr , `
81
- - name: test-compose-package
87
+ expectedYaml := `- name: test-compose-package
82
88
description: A contrived example for podinfo using many Zarf primitives for compose testing
83
89
required: true
84
90
only:
85
91
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
99
107
charts:
100
108
- name: podinfo-compose
101
109
version: 6.4.0
@@ -112,39 +120,6 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
112
120
releaseName: podinfo-compose-two
113
121
valuesFiles:
114
122
- 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 , `
148
123
dataInjections:
149
124
- source: files
150
125
target:
@@ -158,10 +133,17 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
158
133
selector: app.kubernetes.io/name=podinfo-compose
159
134
container: podinfo
160
135
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
165
147
actions:
166
148
onCreate:
167
149
before:
@@ -177,17 +159,16 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
177
159
kind: deployment
178
160
name: podinfo-compose-two
179
161
namespace: podinfo-compose-two
180
- condition: available` )
162
+ condition: available
163
+ `
164
+ require .Equal (t , expectedYaml , string (b ))
181
165
}
182
166
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 ()
190
169
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" )
193
174
}
0 commit comments