@@ -386,37 +386,43 @@ func TestProcSelfFdPath_DeadDir(t *testing.T) {
386386 })
387387}
388388
389- func testVerifyProcRoot (t * testing.T , procRoot string , expectedErr error , errString string ) {
389+ func testVerifyProcRoot (t * testing.T , procRoot string , expectedHandleErr , expectedRootErr error , errString string ) {
390390 fakeProcRoot , err := os .OpenFile (procRoot , unix .O_PATH | unix .O_CLOEXEC , 0 )
391391 require .NoError (t , err )
392392 defer fakeProcRoot .Close () //nolint:errcheck // test code
393393
394394 err = verifyProcRoot (fakeProcRoot )
395- require .ErrorIsf (t , err , expectedErr , "verifyProcRoot(%s)" , procRoot )
396- if expectedErr != nil {
395+ require .ErrorIsf (t , err , expectedRootErr , "verifyProcRoot(%s)" , procRoot )
396+ if expectedRootErr != nil {
397397 require .ErrorContainsf (t , err , errString , "verifyProcRoot(%s)" , procRoot )
398398 }
399+
400+ err = verifyProcHandle (fakeProcRoot )
401+ require .ErrorIsf (t , err , expectedHandleErr , "verifyProcHandle(%s)" , procRoot )
402+ if expectedHandleErr != nil {
403+ require .ErrorContainsf (t , err , errString , "verifyProcHandle(%s)" , procRoot )
404+ }
399405}
400406
401407func TestVerifyProcRoot_Regular (t * testing.T ) {
402408 testForceProcThreadSelf (t , func (t * testing.T ) {
403- testVerifyProcRoot (t , "/proc" , nil , "" )
409+ testVerifyProcRoot (t , "/proc" , nil , nil , "" )
404410 })
405411}
406412
407413func TestVerifyProcRoot_ProcNonRoot (t * testing.T ) {
408414 testForceProcThreadSelf (t , func (t * testing.T ) {
409- testVerifyProcRoot (t , "/proc/self" , errUnsafeProcfs , "incorrect procfs root inode number" )
410- testVerifyProcRoot (t , "/proc/mounts" , errUnsafeProcfs , "incorrect procfs root inode number" )
411- testVerifyProcRoot (t , "/proc/stat" , errUnsafeProcfs , "incorrect procfs root inode number" )
415+ testVerifyProcRoot (t , "/proc/self" , nil , errUnsafeProcfs , "incorrect procfs root inode number" )
416+ testVerifyProcRoot (t , "/proc/mounts" , nil , errUnsafeProcfs , "incorrect procfs root inode number" )
417+ testVerifyProcRoot (t , "/proc/stat" , nil , errUnsafeProcfs , "incorrect procfs root inode number" )
412418 })
413419}
414420
415421func TestVerifyProcRoot_NotProc (t * testing.T ) {
416422 testForceProcThreadSelf (t , func (t * testing.T ) {
417- testVerifyProcRoot (t , "/" , errUnsafeProcfs , "incorrect procfs root filesystem type" )
418- testVerifyProcRoot (t , "." , errUnsafeProcfs , "incorrect procfs root filesystem type" )
419- testVerifyProcRoot (t , t .TempDir (), errUnsafeProcfs , "incorrect procfs root filesystem type" )
423+ testVerifyProcRoot (t , "/" , errUnsafeProcfs , errUnsafeProcfs , "incorrect procfs root filesystem type" )
424+ testVerifyProcRoot (t , "." , errUnsafeProcfs , errUnsafeProcfs , "incorrect procfs root filesystem type" )
425+ testVerifyProcRoot (t , t .TempDir (), errUnsafeProcfs , errUnsafeProcfs , "incorrect procfs root filesystem type" )
420426 })
421427}
422428
0 commit comments