Skip to content

Commit 97de61b

Browse files
committed
Make base image input to functional tests more generic.
1. Change base image info from a set of parameters to a combined struct. This will make it eaiser to pass the info around. It also makes it easier to add additional properties. 2. Change the default base image from a constant to a priority list. This will make it easier to manually run the image independent tests on other images.
1 parent ddc0cbe commit 97de61b

20 files changed

Lines changed: 225 additions & 226 deletions

toolkit/tools/pkg/imagecustomizerlib/artifactsinputoutput_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestOutputAndInjectArtifacts(t *testing.T) {
15-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
15+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
1616

1717
ukifyExists, err := file.CommandExists("ukify")
1818
assert.NoError(t, err)

toolkit/tools/pkg/imagecustomizerlib/customizebootloader_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@ import (
1313
)
1414

1515
func TestCustomizeImageMultiKernel(t *testing.T) {
16-
for _, version := range supportedAzureLinuxVersions {
17-
t.Run(string(version), func(t *testing.T) {
18-
testCustomizeImageMultiKernel(t, "TestCustomizeImageMultiKernel"+string(version),
19-
baseImageTypeCoreEfi, version)
16+
for _, baseImageInfo := range baseImageAll {
17+
t.Run(baseImageInfo.Name, func(t *testing.T) {
18+
testCustomizeImageMultiKernel(t, "TestCustomizeImageMultiKernel"+baseImageInfo.Name, baseImageInfo)
2019
})
2120
}
2221
}
2322

24-
func testCustomizeImageMultiKernel(t *testing.T, testName string, imageType baseImageType,
25-
imageVersion baseImageVersion,
26-
) {
27-
baseImage := checkSkipForCustomizeImage(t, imageType, imageVersion)
23+
func testCustomizeImageMultiKernel(t *testing.T, testName string, baseImageInfo testBaseImageInfo) {
24+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
2825

2926
testTmpDir := filepath.Join(tmpDir, testName)
3027
buildDir := filepath.Join(testTmpDir, "build")
3128
outImageFilePath := filepath.Join(testTmpDir, "image.raw")
3229

3330
configFile := ""
34-
switch imageVersion {
31+
switch baseImageInfo.Version {
3532
case baseImageVersionAzl2:
3633
configFile = filepath.Join(testDir, "multikernel-azl2.yaml")
3734

@@ -60,7 +57,7 @@ func testCustomizeImageMultiKernel(t *testing.T, testName string, imageType base
6057
linuxCommandRegex := regexp.MustCompile(`linux.* console=tty0 console=ttyS0 `)
6158
matches := linuxCommandRegex.FindAllString(grubCfgContents, -1)
6259

63-
switch imageVersion {
60+
switch baseImageInfo.Version {
6461
case baseImageVersionAzl2:
6562
// AZL2's default grub.cfg file doesn't support multiple kernels.
6663
assert.GreaterOrEqual(t, len(matches), 1, "grub.cfg:\n%s", grubCfgContents)

toolkit/tools/pkg/imagecustomizerlib/customizefiles_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
7171
}
7272

7373
func TestCustomizeImageAdditionalFiles(t *testing.T) {
74-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
74+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
7575

7676
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalFiles")
7777
buildDir := filepath.Join(testTmpDir, "build")
@@ -117,7 +117,7 @@ func TestCustomizeImageAdditionalFiles(t *testing.T) {
117117
}
118118

119119
func TestCustomizeImageAdditionalFilesInfiniteFile(t *testing.T) {
120-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
120+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
121121

122122
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalFilesInfiniteFile")
123123
buildDir := filepath.Join(testTmpDir, "build")
@@ -193,7 +193,7 @@ func TestCopyAdditionalDirs(t *testing.T) {
193193
}
194194

195195
func TestCustomizeImageAdditionalDirs(t *testing.T) {
196-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
196+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
197197

198198
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalDirs")
199199
buildDir := filepath.Join(testTmpDir, "build")
@@ -222,7 +222,7 @@ func TestCustomizeImageAdditionalDirs(t *testing.T) {
222222
}
223223

224224
func TestCustomizeImageAdditionalDirsInfiniteFile(t *testing.T) {
225-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
225+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
226226

227227
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalDirsInfiniteFile")
228228
buildDir := filepath.Join(testTmpDir, "build")

toolkit/tools/pkg/imagecustomizerlib/customizehostname_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestUpdateHostname(t *testing.T) {
3939
}
4040

4141
func TestCustomizeImageHostname(t *testing.T) {
42-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
42+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
4343

4444
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageHostname")
4545
buildDir := filepath.Join(testTmpDir, "build")

toolkit/tools/pkg/imagecustomizerlib/customizeoverlays_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestCustomizeImageOverlays(t *testing.T) {
18-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
18+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
1919

2020
testTempDir := filepath.Join(tmpDir, "TestCustomizeImageOverlays")
2121
buildDir := filepath.Join(testTempDir, "build")
@@ -79,7 +79,7 @@ func TestCustomizeImageOverlays(t *testing.T) {
7979
}
8080

8181
func TestCustomizeImageOverlaysSELinux(t *testing.T) {
82-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
82+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
8383

8484
testTempDir := filepath.Join(tmpDir, "TestCustomizeImageOverlaysSELinux")
8585
buildDir := filepath.Join(testTempDir, "build")

toolkit/tools/pkg/imagecustomizerlib/customizepackages_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
func TestCustomizeImagePackagesAddOfflineDir(t *testing.T) {
2222
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesAddOfflineDir")
2323

24-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
24+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
2525
downloadedRpmsDir := getDownloadedRpmsDir(t, "2.0")
2626

2727
buildDir := filepath.Join(testTmpDir, "build")
@@ -146,7 +146,7 @@ func TestCustomizeImagePackagesAddOfflineLocalRepoNoGpgKey(t *testing.T) {
146146
func testCustomizeImagePackagesAddOfflineLocalRepoHelper(t *testing.T, testName string, withGpgKey bool) {
147147
testTmpDir := filepath.Join(tmpDir, testName)
148148

149-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
149+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
150150

151151
downloadedRpmsRepoFile := getDownloadedRpmsRepoFile(t, "2.0", withGpgKey)
152152
rpmSources := []string{downloadedRpmsRepoFile}
@@ -176,7 +176,7 @@ func testCustomizeImagePackagesAddOfflineLocalRepoHelper(t *testing.T, testName
176176
}
177177

178178
func TestCustomizeImagePackagesUpdate(t *testing.T) {
179-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
179+
baseImage, baseImageInfo := checkSkipForCustomizeDefaultImage(t)
180180

181181
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesUpdate")
182182
buildDir := filepath.Join(testTmpDir, "build")
@@ -198,7 +198,7 @@ func TestCustomizeImagePackagesUpdate(t *testing.T) {
198198
defer imageConnection.Close()
199199

200200
// Ensure tdnf cache was cleaned.
201-
ensureTdnfCacheCleanup(t, imageConnection, "/var/cache/tdnf")
201+
ensureTdnfCacheCleanup(t, imageConnection, "/var/cache/tdnf", baseImageInfo)
202202

203203
// Ensure packages were installed.
204204
ensureFilesExist(t, imageConnection,
@@ -212,7 +212,7 @@ func TestCustomizeImagePackagesUpdate(t *testing.T) {
212212
}
213213

214214
func TestCustomizeImagePackagesDiskSpace(t *testing.T) {
215-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
215+
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
216216

217217
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesDiskSpace")
218218
buildDir := filepath.Join(testTmpDir, "build")
@@ -228,7 +228,8 @@ func TestCustomizeImagePackagesDiskSpace(t *testing.T) {
228228
}
229229

230230
func TestCustomizeImagePackagesUrlSource(t *testing.T) {
231-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
231+
baseImageInfo := testBaseImageAzl3CoreEfi
232+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
232233

233234
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesUrlSource")
234235
buildDir := filepath.Join(testTmpDir, "build")
@@ -258,7 +259,8 @@ func TestCustomizeImagePackagesUrlSource(t *testing.T) {
258259
}
259260

260261
func TestCustomizeImagePackagesBadRepo(t *testing.T) {
261-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
262+
baseImageInfo := testBaseImageAzl3CoreEfi
263+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
262264

263265
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesBadRepo")
264266
buildDir := filepath.Join(testTmpDir, "build")
@@ -274,7 +276,9 @@ func TestCustomizeImagePackagesBadRepo(t *testing.T) {
274276
assert.ErrorContains(t, err, "failed to refresh tdnf repo metadata")
275277
}
276278

277-
func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirPath string) {
279+
func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirPath string,
280+
baseImageInfo testBaseImageInfo,
281+
) {
278282
// Array to capture all the files of the provided root directory
279283
var existingFiles []string
280284

@@ -285,7 +289,7 @@ func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirP
285289
return fmt.Errorf("Failed to access path (%s): %w", path, err)
286290
}
287291
// Ignore files in the local-repo folder if the base image version is 2.0
288-
if !(strings.Contains(path, "local-repo") && baseImageVersionDefault == "2.0") {
292+
if !(strings.Contains(path, "local-repo") && baseImageInfo.Version == baseImageVersionAzl2) {
289293
fileInfo, err := os.Stat(path)
290294
if err != nil {
291295
return fmt.Errorf("failed to get file info for %s: %w", path, err)
@@ -307,7 +311,8 @@ func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirP
307311
func TestCustomizeImagePackagesSnapshotTime(t *testing.T) {
308312
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesSnapshotTime")
309313

310-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
314+
baseImageInfo := testBaseImageAzl3CoreEfi
315+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
311316
buildDir := filepath.Join(testTmpDir, "build")
312317
outImageFilePath := filepath.Join(testTmpDir, "image.raw")
313318

@@ -355,7 +360,8 @@ func TestCustomizeImagePackagesSnapshotTime(t *testing.T) {
355360
func TestCustomizeImagePackagesCliSnapshotTimeOverridesConfigFile(t *testing.T) {
356361
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesSnapshotTime")
357362

358-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
363+
baseImageInfo := testBaseImageAzl3CoreEfi
364+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
359365
buildDir := filepath.Join(testTmpDir, "build")
360366
outImageFilePath := filepath.Join(testTmpDir, "image.raw")
361367
snapshotTimeConfig := "2025-03-19"
@@ -403,7 +409,8 @@ func TestCustomizeImagePackagesCliSnapshotTimeOverridesConfigFile(t *testing.T)
403409
func TestCustomizeImagePackagesSnapshotTimeWithoutPreviewFlagFails(t *testing.T) {
404410
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesSnapshotTimeWithoutPreviewFlagFails")
405411

406-
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
412+
baseImageInfo := testBaseImageAzl3CoreEfi
413+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
407414

408415
buildDir := filepath.Join(testTmpDir, "build")
409416
outImageFilePath := filepath.Join(testTmpDir, "image.raw")

0 commit comments

Comments
 (0)