Skip to content

Commit

Permalink
lookup: clean up test helper
Browse files Browse the repository at this point in the history
Fixes: b6aed59 ("lookup: add tests for partialLookupInRoot")
Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Jul 10, 2024
1 parent fbc8097 commit a91c705
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lookup_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@ func checkPartialLookup(t *testing.T, partialLookupFn partialLookupFunc, rootDir
if handle != nil {
defer handle.Close()
}
if expected.err == nil {
if assert.NoError(t, err) {
// Check the remainingPath.
assert.Equal(t, expected.remainingPath, remainingPath, "remaining path")

// Check the handle filepath.
gotPath, err := procSelfFdReadlink(handle)
require.NoError(t, err, "get real path of returned handle")
assert.Equal(t, expected.handlePath, gotPath, "real handle path")
// Make sure the handle matches the readlink filepath.
assert.Equal(t, gotPath, handle.Name(), "handle.Name() matching real handle path")

// Check the handle type.
unixStat, err := fstat(handle)
require.NoError(t, err, "fstat handle")
assert.Equal(t, expected.fileType, unixStat.Mode&unix.S_IFMT, "handle S_IFMT type")
}
} else {
if expected.err != nil {
if assert.Error(t, err) {
assert.ErrorIs(t, err, expected.err)
} else {
t.Errorf("unexpected handle %q", handle.Name())
}
return
}
assert.NoError(t, err)

// Check the remainingPath.
assert.Equal(t, expected.remainingPath, remainingPath, "remaining path")

// Check the handle path.
gotPath, err := procSelfFdReadlink(handle)
require.NoError(t, err, "get real path of returned handle")
assert.Equal(t, expected.handlePath, gotPath, "real handle path")
// Make sure the handle matches the readlink path.
assert.Equal(t, gotPath, handle.Name(), "handle.Name() matching real handle path")

// Check the handle type.
unixStat, err := fstat(handle)
require.NoError(t, err, "fstat handle")
assert.Equal(t, expected.fileType, unixStat.Mode&unix.S_IFMT, "handle S_IFMT type")
}

func testPartialLookup(t *testing.T, partialLookupFn partialLookupFunc) {
Expand Down

0 comments on commit a91c705

Please sign in to comment.