diff --git a/procfs_linux.go b/procfs_linux.go index ba179de..8cc827d 100644 --- a/procfs_linux.go +++ b/procfs_linux.go @@ -425,17 +425,16 @@ func checkProcSelfFdPath(path string, file *os.File) error { return nil } -// Test hooks -var hookForcePrivateProcRootOpenTree = func(_ *os.File) bool { - return false -} - -var hookForcePrivateProcRootOpenTreeAtRecursive = hookForcePrivateProcRootOpenTree - -var hookForceGetProcRootUnsafe = func() bool { - return false -} +// Test hooks used in the procfs tests to verify that the fallback logic works. +// See testing_mocks_linux_test.go and procfs_linux_test.go for more details. +var ( + hookForcePrivateProcRootOpenTree = hookDummyFile + hookForcePrivateProcRootOpenTreeAtRecursive = hookDummyFile + hookForceGetProcRootUnsafe = hookDummy -var hookForceProcSelfTask = hookForceGetProcRootUnsafe + hookForceProcSelfTask = hookDummy + hookForceProcSelf = hookDummy +) -var hookForceProcSelf = hookForceGetProcRootUnsafe +func hookDummy() bool { return false } +func hookDummyFile(_ *os.File) bool { return false } diff --git a/procfs_linux_test.go b/procfs_linux_test.go index 5f7f9a1..61bfed6 100644 --- a/procfs_linux_test.go +++ b/procfs_linux_test.go @@ -418,3 +418,8 @@ func TestVerifyProcRoot_NotProc(t *testing.T) { testVerifyProcRoot(t, t.TempDir(), errUnsafeProcfs, "incorrect procfs root filesystem type") }) } + +func TestProcfsDummyHooks(t *testing.T) { + assert.False(t, hookDummy(), "hookDummy should always return false") + assert.False(t, hookDummyFile(nil), "hookDummyFile should always return false") +} diff --git a/testing_mocks_linux_test.go b/testing_mocks_linux_test.go index c3d554c..d7a2bf5 100644 --- a/testing_mocks_linux_test.go +++ b/testing_mocks_linux_test.go @@ -71,6 +71,7 @@ func init() { hookForceGetProcRootUnsafe = testingForceGetProcRootUnsafe hookForcePrivateProcRootOpenTree = testingForcePrivateProcRootOpenTree hookForcePrivateProcRootOpenTreeAtRecursive = testingForcePrivateProcRootOpenTreeAtRecursive + hookForceProcSelf = testingForceProcSelf hookForceProcSelfTask = testingForceProcSelfTask }