Skip to content

Commit

Permalink
distro/fedora: add tests for boot mode
Browse files Browse the repository at this point in the history
The same tests as added several commits ago for rhel8, 9 and 10.
  • Loading branch information
ondrejbudai committed Dec 2, 2024
1 parent 03febf5 commit b38df56
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions pkg/distro/fedora/distro_internal_test.go
Original file line number Diff line number Diff line change
@@ -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"))
}

})
}
}

}
}

0 comments on commit b38df56

Please sign in to comment.