Skip to content

Commit ea8a505

Browse files
committed
support env vars substitution into the integration tests custom comparison functions. Add RELEASE_IMAGE env var.
1 parent 9376c2f commit ea8a505

File tree

8 files changed

+54
-10
lines changed

8 files changed

+54
-10
lines changed

cmd/openshift-install/agent_internal_integration_test.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"github.com/rogpeppe/go-internal/testscript"
2020
"github.com/stretchr/testify/assert"
2121
"github.com/vincent-petithory/dataurl"
22+
23+
"github.com/openshift/installer/pkg/asset/releaseimage"
2224
)
2325

2426
// This file contains a number of functions useful for
@@ -101,6 +103,14 @@ func runIntegrationTest(t *testing.T, testFolder string) {
101103
}
102104
}
103105

106+
// Let's get the current release version, so that
107+
// it could be used within the tests
108+
pullspec, err := releaseimage.Default()
109+
if err != nil {
110+
return err
111+
}
112+
e.Vars = append(e.Vars, fmt.Sprintf("RELEASE_IMAGE=%s", pullspec))
113+
104114
return nil
105115
},
106116

@@ -111,6 +121,7 @@ func runIntegrationTest(t *testing.T, testFolder string) {
111121
"initrdImgContains": initrdImgContains,
112122
"unconfiguredIgnContains": unconfiguredIgnContains,
113123
"unconfiguredIgnCmp": unconfiguredIgnCmp,
124+
"expandFile": expandFile,
114125
},
115126
})
116127
}
@@ -157,7 +168,6 @@ func archiveFileNames(isoPath string) (string, string, error) {
157168
return "", "", errors.NotFound(fmt.Sprintf("ISO %s has unrecognized prefix", isoPath))
158169
}
159170

160-
// [!] ignitionContains `isoPath` `file` check if the specified file `file`
161171
// [!] unconfiguredIgnContains `file` check if the specified file `file`
162172
// is stored within the unconfigured ignition Storage Files.
163173
func unconfiguredIgnContains(ts *testscript.TestScript, neg bool, args []string) {
@@ -200,6 +210,7 @@ func ignitionStorageContains(ts *testscript.TestScript, neg bool, args []string)
200210
// [!] isoCmp `isoPath` `isoFile` `expectedFile` check that the content of the file
201211
// `isoFile` - extracted from the ISO embedded configuration file referenced
202212
// by `isoPath` - matches the content of the local file `expectedFile`.
213+
// Environment variables in in `expectedFile` are substituted before the comparison.
203214
func isoCmp(ts *testscript.TestScript, neg bool, args []string) {
204215
if len(args) != 3 {
205216
ts.Fatalf("usage: isocmp isoPath file1 file2")
@@ -227,6 +238,7 @@ func isoCmp(ts *testscript.TestScript, neg bool, args []string) {
227238
// [!] unconfiguredIgnCmp `fileInIgn` `expectedFile` check that the content
228239
// of the file `fileInIgn` extracted from the unconfigured ignition
229240
// configuration file matches the content of the local file `expectedFile`.
241+
// Environment variables in in `expectedFile` are substituted before the comparison.
230242
func unconfiguredIgnCmp(ts *testscript.TestScript, neg bool, args []string) {
231243
if len(args) != 2 {
232244
ts.Fatalf("usage: iunconfiguredIgnCmp file1 file2")
@@ -238,6 +250,7 @@ func unconfiguredIgnCmp(ts *testscript.TestScript, neg bool, args []string) {
238250
// [!] ignitionStorageCmp `ignPath` `ignFile` `expectedFile` check that the content of the file
239251
// `ignFile` - extracted from the ignition configuration file referenced
240252
// by `ignPath` - matches the content of the local file `expectedFile`.
253+
// Environment variables in in `expectedFile` are substituted before the comparison.
241254
func ignitionStorageCmp(ts *testscript.TestScript, neg bool, args []string) {
242255
if len(args) != 3 {
243256
ts.Fatalf("usage: ignitionStorageCmp ignPath file1 file2")
@@ -267,9 +280,34 @@ func readIgnition(ts *testscript.TestScript, ignPath string) (config igntypes.Co
267280
return config, err
268281
}
269282

283+
// [!] expandFile `file...` can be used to substitute environment variables
284+
// references for each file specified
285+
func expandFile(ts *testscript.TestScript, neg bool, args []string) {
286+
if len(args) != 1 {
287+
ts.Fatalf("usage: expandFile file...")
288+
}
289+
290+
workDir := ts.Getenv("WORK")
291+
for _, f := range args {
292+
fileName := filepath.Join(workDir, f)
293+
data, err := os.ReadFile(fileName)
294+
ts.Check(err)
295+
296+
newData := expand(ts, data)
297+
err = os.WriteFile(fileName, []byte(newData), 0)
298+
ts.Check(err)
299+
}
300+
}
301+
302+
func expand(ts *testscript.TestScript, s []byte) string {
303+
return os.Expand(string(s), func(key string) string {
304+
return ts.Getenv(key)
305+
})
306+
}
307+
270308
func byteCompare(ts *testscript.TestScript, neg bool, aData, eData []byte, aFilePath, eFilePath string) {
271309
aText := string(aData)
272-
eText := string(eData)
310+
eText := expand(ts, eData)
273311

274312
eq := aText == eText
275313
if neg {

cmd/openshift-install/testdata/agent/configimage/manifests/default_manifests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ metadata:
100100
name: openshift-was not built correctly
101101
namespace: cluster0
102102
spec:
103-
releaseImage: registry.ci.openshift.org/origin/release:4.14
103+
releaseImage: $RELEASE_IMAGE
104104
status: {}
105105
-- expected/pull-secret.yaml --
106106
apiVersion: v1

cmd/openshift-install/testdata/agent/image/manifests/default_manifests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ metadata:
101101
name: openshift-was not built correctly
102102
namespace: cluster0
103103
spec:
104-
releaseImage: registry.ci.openshift.org/origin/release:4.14
104+
releaseImage: $RELEASE_IMAGE
105105
status: {}
106106
-- expected/infraenv.yaml --
107107
metadata:

cmd/openshift-install/testdata/agent/unconfigured-ignition/configurations/from-ztp-manifests.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# and not using
44
# install-config.yaml and agent-config.yaml.
55

6+
expandFile cluster-manifests/cluster-image-set.yaml
7+
68
exec openshift-install agent create unconfigured-ignition --dir $WORK
79

810
exists $WORK/unconfigured-agent.ign
@@ -45,14 +47,14 @@ metadata:
4547
name: cluster0-image-set
4648
namespace: cluster0
4749
spec:
48-
releaseImage: registry.ci.openshift.org/origin/release:4.14
50+
releaseImage: $RELEASE_IMAGE
4951

5052
-- expected/cluster-image-set.yaml --
5153
metadata:
5254
name: cluster0-image-set
5355
namespace: cluster0
5456
spec:
55-
releaseImage: registry.ci.openshift.org/origin/release:4.14
57+
releaseImage: $RELEASE_IMAGE
5658

5759
-- expected/infraenv.yaml --
5860
metadata:

cmd/openshift-install/testdata/agent/unconfigured-ignition/manifests/default_manifests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ metadata:
5353
name: openshift-was not built correctly
5454
namespace: cluster0
5555
spec:
56-
releaseImage: registry.ci.openshift.org/origin/release:4.14
56+
releaseImage: $RELEASE_IMAGE
5757
status: {}
5858
-- expected/infraenv.yaml --
5959
metadata:

cmd/openshift-install/testdata/agent/unconfigured-ignition/validations/missing-cluster-image-set-allowed.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ metadata:
4444
creationTimestamp: null
4545
name: openshift-was not built correctly
4646
spec:
47-
releaseImage: registry.ci.openshift.org/origin/release:4.14
47+
releaseImage: $RELEASE_IMAGE
4848
status: {}

cmd/openshift-install/testdata/agent/unconfigured-ignition/validations/missing-infraenv.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Missing infraenv.yaml should be detected.
22

3+
expandFile cluster-manifests/cluster-image-set.yaml
4+
35
! exec openshift-install agent create unconfigured-ignition --dir $WORK
46

57
stderr 'failed to generate asset "InfraEnv Config": missing configuration or manifest file'
@@ -13,7 +15,7 @@ metadata:
1315
name: cluster0-image-set
1416
namespace: cluster0
1517
spec:
16-
releaseImage: registry.ci.openshift.org/origin/release:4.14
18+
releaseImage: $RELEASE_IMAGE
1719

1820
-- cluster-manifests/pull-secret.yaml --
1921
apiVersion: v1

cmd/openshift-install/testdata/agent/unconfigured-ignition/validations/missing-pull-secret.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Missing pull-secret.yaml should be detected.
22

3+
expandFile cluster-manifests/cluster-image-set.yaml
4+
35
! exec openshift-install agent create unconfigured-ignition --dir $WORK
46

57
stderr 'failed to generate asset "Agent PullSecret": missing configuration or manifest file'
@@ -23,5 +25,5 @@ metadata:
2325
name: cluster0-image-set
2426
namespace: cluster0
2527
spec:
26-
releaseImage: registry.ci.openshift.org/origin/release:4.14
28+
releaseImage: $RELEASE_IMAGE
2729

0 commit comments

Comments
 (0)