Skip to content

Commit

Permalink
disk: change invalid boot mode error and add test
Browse files Browse the repository at this point in the history
The previous error message was printing an invalid enum value as a
string, which would cause a panic in the BootMode.String() method.

Update the error in the AddPartitionsForBootMode() function and add a
test.
  • Loading branch information
achilleas-k authored and mvo5 committed Nov 7, 2024
1 parent 601f722 commit 863bb93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ func AddPartitionsForBootMode(pt *PartitionTable, bootMode platform.BootMode) er
case platform.BOOT_NONE:
return nil
default:
return fmt.Errorf("invalid boot mode specified: %s", bootMode)
return fmt.Errorf("unknown or unsupported boot mode type with enum value %d", bootMode)
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/disk/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ func TestAddPartitionsForBootMode(t *testing.T) {
bootMode: platform.BOOT_HYBRID,
errmsg: "error creating BIOS boot partition: unknown or unsupported partition table type: super-gpt",
},
"bad-bootmode": {
pt: disk.PartitionTable{Type: "gpt"},
bootMode: 4,
errmsg: "unknown or unsupported boot mode type with enum value 4",
},
}

for name := range testCases {
Expand Down

0 comments on commit 863bb93

Please sign in to comment.