From b38df56ca7dea477a818a748158ea18ce790f2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Mon, 2 Dec 2024 13:09:06 +0100 Subject: [PATCH] distro/fedora: add tests for boot mode The same tests as added several commits ago for rhel8, 9 and 10. --- pkg/distro/fedora/distro_internal_test.go | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 pkg/distro/fedora/distro_internal_test.go diff --git a/pkg/distro/fedora/distro_internal_test.go b/pkg/distro/fedora/distro_internal_test.go new file mode 100644 index 0000000000..6b777f94ed --- /dev/null +++ b/pkg/distro/fedora/distro_internal_test.go @@ -0,0 +1,58 @@ +package fedora + +import ( + "fmt" + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/osbuild/images/pkg/blueprint" + "github.com/osbuild/images/pkg/distro" + "github.com/osbuild/images/pkg/platform" +) + +// math/rand is good enough in this case +/* #nosec G404 */ +var rng = rand.New(rand.NewSource(0)) + +// TestESP checks whether all UEFI and hybrid images with a partition table have an ESP partition. +// It also checks the opposite, i.e. that legacy images don't have an ESP. This test is only +// performed on image types with a partition table, thus it doesn't run on e.g. installers and +// ostree commits. +func TestESP(t *testing.T) { + distros := []string{"fedora-40", "fedora-41", "fedora-42"} + for _, distroName := range distros { + d := DistroFactory(distroName) + + for _, archName := range d.ListArches() { + a, err := d.GetArch(archName) + require.NoError(t, err) + + for _, itName := range a.ListImageTypes() { + i, err := a.GetImageType(itName) + require.NoError(t, err) + + it := i.(*imageType) + // Nothing to test if the type doesn't have a base partition table. + if it.basePartitionTables == nil { + continue + } + + t.Run(fmt.Sprintf("%s/%s/%s", distroName, archName, itName), func(t *testing.T) { + pt, err := it.getPartitionTable(&blueprint.Customizations{}, distro.ImageOptions{}, rng) + require.NoError(t, err) + + switch it.BootMode() { + case platform.BOOT_HYBRID, platform.BOOT_UEFI: + require.NotNil(t, pt.FindMountable("/boot/efi")) + default: + require.Nil(t, pt.FindMountable("/boot/efi")) + } + + }) + } + } + + } +}