Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd8fa2c

Browse files
committedNov 29, 2024·
disk: update TestPartitionTableFeatures() to catch missing test case
Update the TestPartitionTableFeatures() to match other tests that use the TestPartitionTables. - Switch to require from assert to stop test execution if something fails. This makes it easier to see the important error message. With assert, execution would continue when `ok` is false, which would make the assert.Equal() test print an error too (exp would be an empty initialised struct of PartitionTableFeatures) and can make it hard to notice that the "expected test result not defined" error was printed first. - Use a map for testCases so we can get each test case by name (the order is not important). - Print the same error message as the other similar tests, using t.Name() to refer to the test function name. - Add plain-noboot test case, which was missing from the test.
1 parent 1934e3e commit dd8fa2c

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed
 

‎pkg/disk/partition_table_test.go‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
89

910
"github.com/osbuild/images/internal/testdisk"
1011
"github.com/osbuild/images/pkg/blueprint"
@@ -2284,21 +2285,24 @@ func TestNewCustomPartitionTableErrors(t *testing.T) {
22842285
}
22852286

22862287
func TestPartitionTableFeatures(t *testing.T) {
2287-
type testCase struct {
2288-
partitionType string
2289-
expectedFeatures disk.PartitionTableFeatures
2290-
}
2291-
testCases := []testCase{
2292-
{"plain", disk.PartitionTableFeatures{XFS: true, FAT: true}},
2293-
{"plain-swap", disk.PartitionTableFeatures{XFS: true, FAT: true, Swap: true}},
2294-
{"luks", disk.PartitionTableFeatures{XFS: true, FAT: true, LUKS: true}},
2295-
{"luks+lvm", disk.PartitionTableFeatures{XFS: true, FAT: true, LUKS: true, LVM: true}},
2296-
{"btrfs", disk.PartitionTableFeatures{XFS: true, FAT: true, Btrfs: true}},
2297-
}
2288+
require := require.New(t)
22982289

2299-
for _, tc := range testCases {
2300-
pt := testdisk.TestPartitionTables[tc.partitionType]
2301-
assert.Equal(t, tc.expectedFeatures, disk.GetPartitionTableFeatures(pt))
2290+
testCases := map[string]disk.PartitionTableFeatures{
2291+
"plain": {XFS: true, FAT: true},
2292+
"plain-noboot": {XFS: true, FAT: true},
2293+
"plain-swap": {XFS: true, FAT: true, Swap: true},
2294+
"luks": {XFS: true, FAT: true, LUKS: true},
2295+
"luks+lvm": {XFS: true, FAT: true, LUKS: true, LVM: true},
2296+
"btrfs": {XFS: true, FAT: true, Btrfs: true},
2297+
}
23022298

2299+
for name := range testdisk.TestPartitionTables {
2300+
// print an informative failure message if a new test partition
2301+
// table is added and this test is not updated (instead of failing
2302+
// at the final Equal() check)
2303+
exp, ok := testCases[name]
2304+
require.True(ok, "expected test result not defined for test partition table %q: please update the %s test", name, t.Name())
2305+
pt := testdisk.TestPartitionTables[name]
2306+
require.Equal(exp, disk.GetPartitionTableFeatures(pt))
23032307
}
23042308
}

0 commit comments

Comments
 (0)
Please sign in to comment.