debian-forge-composer/internal/osbuild2/disk_test.go
Christian Kellner 2c6e726c94 disk: add new GenImageKernelOptions helper
This creates the needed kernel options for an image, if any,
based on the partition table.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00

40 lines
904 B
Go

package osbuild2
import (
"math/rand"
"testing"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/stretchr/testify/assert"
)
func TestGenImageKernelOptions(t *testing.T) {
assert := assert.New(t)
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(rand.NewSource(13))
luks_lvm := testPartitionTables["luks+lvm"]
pt, err := disk.NewPartitionTable(&luks_lvm, []blueprint.FilesystemCustomization{}, 0, rng)
assert.NoError(err)
var uuid string
findLuksUUID := func(e disk.Entity, path []disk.Entity) error {
switch ent := e.(type) {
case *disk.LUKSContainer:
uuid = ent.UUID
}
return nil
}
_ = pt.ForEachEntity(findLuksUUID)
assert.NotEmpty(uuid, "Could not find LUKS container")
cmdline := GenImageKernelOptions(pt)
assert.Subset(cmdline, []string{"luks.uuid=" + uuid})
}