Skip to content

Commit a403314

Browse files
committed
Unit tests reviewed
1 parent 522ac40 commit a403314

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/liveosisobuilder_test.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ import (
2525

2626
func createConfig(fileName, kernelParameter string, initramfsType imagecustomizerapi.InitramfsImageType, bootstrapFileUrl string,
2727
enableOsConfig, bootstrapPrereqs bool, selinuxMode imagecustomizerapi.SELinuxMode) *imagecustomizerapi.Config {
28-
2928
bootstrapRequiredPkgs := []string{}
3029
if bootstrapPrereqs {
31-
bootstrapRequiredPkgs = []string{
32-
"squashfs-tools",
33-
"tar",
34-
"device-mapper",
35-
"curl",
36-
}
30+
bootstrapRequiredPkgs = append(bootstrapRequiredPkgs, "squashfs-tools", "tar", "device-mapper", "curl")
3731
}
38-
3932
if selinuxMode != imagecustomizerapi.SELinuxModeDisabled {
4033
bootstrapRequiredPkgs = append(bootstrapRequiredPkgs, "selinux-policy")
4134
}
@@ -94,10 +87,9 @@ func createConfig(fileName, kernelParameter string, initramfsType imagecustomize
9487
return &config
9588
}
9689

97-
func VerifyBootstrapPresence(t *testing.T, initramfsType imagecustomizerapi.InitramfsImageType, bootstrapImagePath string) {
98-
99-
bootstrapImageExists, err := file.PathExists(bootstrapImagePath)
100-
assert.NoErrorf(t, err, "check if (%s) bootstrapImagePath exists", bootstrapImagePath)
90+
func VerifyBootstrappedImageExists(t *testing.T, initramfsType imagecustomizerapi.InitramfsImageType, bootstrappedImagePath string) {
91+
bootstrapImageExists, err := file.PathExists(bootstrappedImagePath)
92+
assert.NoErrorf(t, err, "check if (%s) bootstrappedImagePath exists", bootstrappedImagePath)
10193

10294
switch initramfsType {
10395
case imagecustomizerapi.InitramfsImageTypeBootstrap:
@@ -108,8 +100,6 @@ func VerifyBootstrapPresence(t *testing.T, initramfsType imagecustomizerapi.Init
108100
}
109101

110102
func ValidateLiveOSContent(t *testing.T, config *imagecustomizerapi.Config, testTempDir, outputFormat string, artifactsPath, bootstrappedImage string) {
111-
112-
// Check for the copied a.txt file.
113103
var additionalFiles imagecustomizerapi.AdditionalFileList
114104
var extraCommandLineParameters []string
115105
var initramfsType imagecustomizerapi.InitramfsImageType
@@ -150,17 +140,17 @@ func ValidateLiveOSContent(t *testing.T, config *imagecustomizerapi.Config, test
150140
assert.Contains(t, savedConfigs.LiveOS.KernelCommandLine.ExtraCommandLine, extraCommandLineParameter)
151141
}
152142

153-
bootstrapImagePath := ""
143+
bootstrappedImagePath := ""
154144
if outputFormat == "iso" {
155145
// The bootstrap file is a squashfs image file
156-
bootstrapImagePath = filepath.Join(artifactsPath, liveOSDir, liveOSImage)
146+
bootstrappedImagePath = filepath.Join(artifactsPath, liveOSDir, liveOSImage)
157147
} else {
158148
// The bootstrap file is an iso that contains the squashfs file
159-
bootstrapImagePath = filepath.Join(artifactsPath, defaultIsoImageName)
149+
bootstrappedImagePath = filepath.Join(artifactsPath, defaultIsoImageName)
160150
}
161151

162-
VerifyBootstrapPresence(t, initramfsType, bootstrapImagePath)
163-
VerifyFullOSContents(t, testTempDir, artifactsPath, outputFormat, config.OS, bootstrapImagePath, initramfsType)
152+
VerifyBootstrappedImageExists(t, initramfsType, bootstrappedImagePath)
153+
VerifyFullOSContents(t, testTempDir, artifactsPath, outputFormat, config.OS, bootstrappedImagePath, initramfsType)
164154

165155
if outputFormat == "pxe" {
166156
if initramfsType == imagecustomizerapi.InitramfsImageTypeBootstrap {
@@ -169,7 +159,7 @@ func ValidateLiveOSContent(t *testing.T, config *imagecustomizerapi.Config, test
169159
}
170160
}
171161

172-
func VerifyFullOSContents(t *testing.T, testTempDir, artifactsPath, outputFormat string, osConfig *imagecustomizerapi.OS, bootstrapImagePath string, initramfsType imagecustomizerapi.InitramfsImageType) {
162+
func VerifyFullOSContents(t *testing.T, testTempDir, artifactsPath, outputFormat string, osConfig *imagecustomizerapi.OS, bootstrappedImagePath string, initramfsType imagecustomizerapi.InitramfsImageType) {
173163
if osConfig == nil {
174164
return
175165
}
@@ -180,10 +170,10 @@ func VerifyFullOSContents(t *testing.T, testTempDir, artifactsPath, outputFormat
180170
fullOSImagePath := ""
181171
if outputFormat == "iso" {
182172
// The full OS image is the bootstrap image
183-
fullOSImagePath = bootstrapImagePath
173+
fullOSImagePath = bootstrappedImagePath
184174
} else {
185175
// The bootstrap file is an iso that contains the squashfs file
186-
isoImageLoopDevice, err := safeloopback.NewLoopback(bootstrapImagePath)
176+
isoImageLoopDevice, err := safeloopback.NewLoopback(bootstrappedImagePath)
187177
if !assert.NoError(t, err) {
188178
return
189179
}

toolkit/tools/pkg/imagecustomizerlib/testdata/iso-bootstrap-vm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
iso:
2-
initramfsType: full-os
2+
initramfsType: bootstrap
33
os:
44
selinux:
55
mode: disabled

toolkit/tools/pkg/imagecustomizerlib/testdata/iso-full-os-vm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
iso:
2-
initramfsType: bootstrap
2+
initramfsType: full-os
33
os:
44
selinux:
55
mode: disabled

0 commit comments

Comments
 (0)