From e734c0c716d5d93d6daca1433491eb6e67d74945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Thu, 29 Aug 2024 12:34:02 +0200 Subject: [PATCH] disk: test that mountpoints from the bp were applied Previously, the test suite didn't check whether the customizations were actually applied to a partition table. This commit adds a tiny function that tests that the correct Muntable is created in the partition table and that all Sizeables above the Mountable have at least the MinSize given by the blueprint. --- pkg/disk/disk_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/disk/disk_test.go b/pkg/disk/disk_test.go index bb6dd0cdbf..96063e7a2f 100644 --- a/pkg/disk/disk_test.go +++ b/pkg/disk/disk_test.go @@ -420,6 +420,26 @@ func TestDisk_ForEachEntity(t *testing.T) { assert.Equal(t, 8, count) } +// blueprintApplied checks if the blueprint was applied correctly +// returns nil if the blueprint was applied correctly, an error otherwise +func blueprintApplied(pt *PartitionTable, bp []blueprint.FilesystemCustomization) error { + for _, mnt := range bp { + path := entityPath(pt, mnt.Mountpoint) + if path == nil { + return fmt.Errorf("mountpoint %s not found", mnt.Mountpoint) + } + for idx, ent := range path { + if sz, ok := ent.(Sizeable); ok { + if sz.GetSize() < mnt.MinSize { + return fmt.Errorf("entity %d in the path from %s is smaller (%d) than the requested minsize %d", idx, mnt.Mountpoint, sz.GetSize(), mnt.MinSize) + } + } + } + } + + return nil +} + func TestCreatePartitionTable(t *testing.T) { assert := assert.New(t) @@ -467,6 +487,7 @@ func TestCreatePartitionTable(t *testing.T) { assert.NotNil(mnt, "PT %q BP %q: failed to find root mountable", ptName, bpName) assert.NoError(mpt.ForEachMountable(sizeCheckCB)) + assert.NoError(blueprintApplied(mpt, bp), "PT %q BP %q: blueprint check failed", ptName, bpName) } } } @@ -504,6 +525,7 @@ func TestCreatePartitionTableLVMify(t *testing.T) { _, ok := parent.(*LVMLogicalVolume) assert.True(ok, "PT %q BP %q: root's parent (%q) is not an LVM logical volume", ptName, bpName, parent) } + assert.NoError(blueprintApplied(mpt, tbp), "PT %q BP %q: blueprint check failed", ptName, bpName) } } } @@ -541,6 +563,7 @@ func TestCreatePartitionTableBtrfsify(t *testing.T) { _, ok := parent.(*Btrfs) assert.True(ok, "PT %q BP %q: root's parent (%+v) is not an btrfs volume but %T", ptName, bpName, parent, parent) } + assert.NoError(blueprintApplied(mpt, tbp), "PT %q BP %q: blueprint check failed", ptName, bpName) } } } @@ -620,6 +643,8 @@ func TestCreatePartitionTableLVMOnly(t *testing.T) { assert.True(ok, "PT %q BP %q: root VG top level entity (%+v) is not a partition", ptName, bpName, rootTop) assert.GreaterOrEqualf(vgPart.Size, lvsum, "PT %q BP %q: VG partition's size (%d) is smaller than the sum of logical volumes (%d)", ptName, bpName, vgPart.Size, lvsum) + + assert.NoError(blueprintApplied(mpt, tbp), "PT %q BP %q: blueprint check failed", ptName, bpName) } } }