Skip to content

Commit

Permalink
disk: bugfix/test for ensureBtrfs()
Browse files Browse the repository at this point in the history
A new test TestCreatePartitionTableBtrfsify was added.

This test also uncovered a small bug in ensureBtrfs() that got
fixed along the way.
  • Loading branch information
mvo5 committed Jul 4, 2024
1 parent 3cc26b6 commit f174a4d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,43 @@ func TestCreatePartitionTableLVMify(t *testing.T) {
}
}

func TestCreatePartitionTableBtrfsify(t *testing.T) {
assert := assert.New(t)
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(rand.NewSource(13))
for bpName, tbp := range testBlueprints {
for ptName := range testPartitionTables {
pt := testPartitionTables[ptName]

if ptName == "auto-lvm" || ptName == "luks" || ptName == "luks+lvm" {
_, err := NewPartitionTable(&pt, tbp, uint64(13*MiB), BtfrsPartitioningMode, nil, rng)
assert.Error(err, "PT %q BP %q: should return an error with BtrfsPartitioningMode", ptName, bpName)
continue
}

mpt, err := NewPartitionTable(&pt, tbp, uint64(13*MiB), BtfrsPartitioningMode, nil, rng)
assert.NoError(err, "PT %q BP %q: Partition table generation failed: (%s)", ptName, bpName, err)

rootPath := entityPath(mpt, "/")
if rootPath == nil {
panic(fmt.Sprintf("PT %q BP %q: no root mountpoint", ptName, bpName))
}

bootPath := entityPath(mpt, "/boot")
if tbp != nil && bootPath == nil {
panic(fmt.Sprintf("PT %q BP %q: no boot mountpoint", ptName, bpName))
}

if tbp != nil {
parent := rootPath[1]
_, 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)
}
}
}
}

func TestCreatePartitionTableLVMOnly(t *testing.T) {
assert := assert.New(t)
// math/rand is good enough in this case
Expand Down
2 changes: 2 additions & 0 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ func (pt *PartitionTable) ensureBtrfs() error {
if err != nil {
return fmt.Errorf("failed to create /boot partition when ensuring btrfs: %w", err)
}

rootPath = entityPath(pt, "/")
}

parent := rootPath[1] // NB: entityPath has reversed order
Expand Down

0 comments on commit f174a4d

Please sign in to comment.