@@ -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.
163173func 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.
203214func 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.
230242func 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.
241254func 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+
270308func 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 {
0 commit comments