From e24b33e89545a2a6810a9dba42e7eb552e487ef6 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 13 Dec 2024 13:53:15 -0800 Subject: [PATCH] image: Add tests for rootfs selection Make sure that the rootfs-image pipeline is present in ext4 images and not present in squashfs only images. --- pkg/image/installer_image_test.go | 134 ++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/pkg/image/installer_image_test.go b/pkg/image/installer_image_test.go index 7ebd17cecc..3a69555fdd 100644 --- a/pkg/image/installer_image_test.go +++ b/pkg/image/installer_image_test.go @@ -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 @@ -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 @@ -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