Skip to content

Commit

Permalink
disk,osbuild: use t.Name() in test update instruction message
Browse files Browse the repository at this point in the history
Use t.Name() in the tests that use the TestPartitionTables and expect
all cases to be covered so that we don't need to keep the message in
sync with the function name.

The message for TestForEachFSTabEntity() was wrong.
  • Loading branch information
achilleas-k committed Nov 29, 2024
1 parent 803ad10 commit 1934e3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions pkg/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,22 +987,23 @@ func TestForEachFSTabEntity(t *testing.T) {
}

for name := range testdisk.TestPartitionTables {
t.Run(name, func(t *testing.T) {

// use a different name for the internal testing argument so we can
// refer to the global test by t.Name() in the error message
t.Run(name, func(ts *testing.T) {
var targets []string
targetCollectorCB := func(ent disk.FSTabEntity, _ []disk.Entity) error {
targets = append(targets, ent.GetFSFile())
return nil
}

require := require.New(t)
require := require.New(ts)
pt := testdisk.TestPartitionTables[name]

// print an informative failure message if a new test partition
// table is added and this test is not updated (instead of failing
// at the final Equal() check)
exp, ok := expectedEntityPaths[name]
require.True(ok, "expected options not defined for test partition table %q: please update the TestNewFSTabStageOptions test", name)
require.True(ok, "expected test result not defined for test partition table %q: please update the %s test", name, t.Name())

err := pt.ForEachFSTabEntity(targetCollectorCB)
// the callback never returns an error, but let's check it anyway
Expand Down
8 changes: 5 additions & 3 deletions pkg/osbuild/fstab_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ func TestNewFSTabStageOptions(t *testing.T) {
}
// Use the test partition tables from the disk package.
for name := range testdisk.TestPartitionTables {
t.Run(name, func(t *testing.T) {
require := require.New(t)
// use a different name for the internal testing argument so we can
// refer to the global test by t.Name() in the error message
t.Run(name, func(ts *testing.T) {
require := require.New(ts)
pt := testdisk.TestPartitionTables[name]

// math/rand is good enough in this case
Expand All @@ -118,7 +120,7 @@ func TestNewFSTabStageOptions(t *testing.T) {
// table is added and this test is not updated (instead of failing
// at the final Equal() check)
exp, ok := expectedOptions[name]
require.True(ok, "expected options not defined for test partition table %q: please update the TestNewFSTabStageOptions test", name)
require.True(ok, "expected test result not defined for test partition table %q: please update the %s test", name, t.Name())

options, err := NewFSTabStageOptions(&pt)
require.NoError(err)
Expand Down

0 comments on commit 1934e3e

Please sign in to comment.