Skip to content

Commit

Permalink
image: Add tests for rootfs selection
Browse files Browse the repository at this point in the history
Make sure that the rootfs-image pipeline is present in ext4 images and
not present in squashfs only images.
  • Loading branch information
bcl committed Dec 13, 2024
1 parent 98994b6 commit e24b33e
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions pkg/image/installer_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ func TestContainerInstallerSetKSPath(t *testing.T) {
assert.NotContains(t, mfs, "osbuild.ks") // no mention of the default value anywhere
}

func TestContainerInstallerExt4Rootfs(t *testing.T) {
img := image.NewAnacondaContainerInstaller(container.SourceSpec{}, "")
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel

assert.NotNil(t, img)
img.Platform = testPlatform
mfs := instantiateAndSerialize(t, img, mockPackageSets(), mockContainerSpecs(), nil)

// Confirm that it includes the rootfs-image pipeline that makes the ext4 rootfs
assert.Contains(t, mfs, `"name":"rootfs-image"`)
assert.Contains(t, mfs, `"name:rootfs-image"`)
}

func TestContainerInstallerSquashfsRootfs(t *testing.T) {
img := image.NewAnacondaContainerInstaller(container.SourceSpec{}, "")
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel
img.RootfsType = image.SquashfsRootfs

assert.NotNil(t, img)
img.Platform = testPlatform
mfs := instantiateAndSerialize(t, img, mockPackageSets(), mockContainerSpecs(), nil)

// Confirm that it does not include rootfs-image pipeline
assert.NotContains(t, mfs, `"name":"rootfs-image"`)
assert.NotContains(t, mfs, `"name:rootfs-image"`)
}

func TestOSTreeInstallerUnsetKSPath(t *testing.T) {
img := image.NewAnacondaOSTreeInstaller(ostree.SourceSpec{})
img.Product = product
Expand Down Expand Up @@ -158,6 +189,47 @@ func TestOSTreeInstallerSetKSPath(t *testing.T) {
assert.NotContains(t, mfs, "osbuild.ks") // no mention of the default value anywhere
}

func TestOSTreeInstallerExt4Rootfs(t *testing.T) {
img := image.NewAnacondaOSTreeInstaller(ostree.SourceSpec{})
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel

assert.NotNil(t, img)
img.Platform = testPlatform
img.Kickstart = &kickstart.Options{
// the ostree options must be non-nil
OSTree: &kickstart.OSTree{},
}

mfs := instantiateAndSerialize(t, img, mockPackageSets(), nil, mockOSTreeCommitSpecs())

// Confirm that it includes the rootfs-image pipeline that makes the ext4 rootfs
assert.Contains(t, mfs, `"name":"rootfs-image"`)
assert.Contains(t, mfs, `"name:rootfs-image"`)
}

func TestOSTreeInstallerSquashfsRootfs(t *testing.T) {
img := image.NewAnacondaOSTreeInstaller(ostree.SourceSpec{})
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel
img.RootfsType = image.SquashfsRootfs

assert.NotNil(t, img)
img.Platform = testPlatform
img.Kickstart = &kickstart.Options{
// the ostree options must be non-nil
OSTree: &kickstart.OSTree{},
}

mfs := instantiateAndSerialize(t, img, mockPackageSets(), nil, mockOSTreeCommitSpecs())

// Confirm that it does not include rootfs-image pipeline
assert.NotContains(t, mfs, `"name":"rootfs-image"`)
assert.NotContains(t, mfs, `"name:rootfs-image"`)
}

func TestTarInstallerUnsetKSOptions(t *testing.T) {
img := image.NewAnacondaTarInstaller()
img.Product = product
Expand Down Expand Up @@ -220,6 +292,68 @@ func TestTarInstallerSetKSPath(t *testing.T) {
assert.NotContains(t, mfs, "osbuild.ks") // no mention of the default value anywhere
}

func TestTarInstallerExt4Rootfs(t *testing.T) {
img := image.NewAnacondaTarInstaller()
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel

assert.NotNil(t, img)
img.Platform = testPlatform

mfs := instantiateAndSerialize(t, img, mockPackageSets(), nil, nil)
// Confirm that it includes the rootfs-image pipeline that makes the ext4 rootfs
assert.Contains(t, mfs, `"name":"rootfs-image"`)
assert.Contains(t, mfs, `"name:rootfs-image"`)
}

func TestTarInstallerSquashfsRootfs(t *testing.T) {
img := image.NewAnacondaTarInstaller()
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel
img.RootfsType = image.SquashfsRootfs

assert.NotNil(t, img)
img.Platform = testPlatform

mfs := instantiateAndSerialize(t, img, mockPackageSets(), nil, nil)
// Confirm that it does not include rootfs-image pipeline
assert.NotContains(t, mfs, `"name":"rootfs-image"`)
assert.NotContains(t, mfs, `"name:rootfs-image"`)
}

func TestLiveInstallerExt4Rootfs(t *testing.T) {
img := image.NewAnacondaLiveInstaller()
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel

assert.NotNil(t, img)
img.Platform = testPlatform

mfs := instantiateAndSerialize(t, img, mockPackageSets(), nil, nil)
// Confirm that it includes the rootfs-image pipeline that makes the ext4 rootfs
assert.Contains(t, mfs, `"name":"rootfs-image"`)
assert.Contains(t, mfs, `"name:rootfs-image"`)
}

func TestLiveInstallerSquashfsRootfs(t *testing.T) {
img := image.NewAnacondaLiveInstaller()
img.Product = product
img.OSVersion = osversion
img.ISOLabel = isolabel
img.RootfsType = image.SquashfsRootfs

assert.NotNil(t, img)
img.Platform = testPlatform

mfs := instantiateAndSerialize(t, img, mockPackageSets(), nil, nil)
// Confirm that it does not include rootfs-image pipeline
assert.NotContains(t, mfs, `"name":"rootfs-image"`)
assert.NotContains(t, mfs, `"name:rootfs-image"`)
}

func instantiateAndSerialize(t *testing.T, img image.ImageKind, packages map[string][]rpmmd.PackageSpec, containers map[string][]container.Spec, commits map[string][]ostree.CommitSpec) string {
source := rand.NewSource(int64(0))
// math/rand is good enough in this case
Expand Down

0 comments on commit e24b33e

Please sign in to comment.