Skip to content

Commit 5d09d69

Browse files
committed
mountinfo: add TestMountedRoot
Test both MountedFast and Mounted. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 303f101 commit 5d09d69

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

mountinfo/mounted_linux_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,24 @@ func TestMountedByOpenat2VsMountinfo(t *testing.T) {
434434
}
435435
}
436436
}
437+
438+
// TestMountedRoot checks that Mounted* functions always return true for root
439+
// directory (since / is always mounted).
440+
func TestMountedRoot(t *testing.T) {
441+
for _, path := range []string{
442+
"/",
443+
"/../../",
444+
"/tmp/..",
445+
strings.Repeat("../", unix.PathMax/3), // Hope $CWD is not too deep down.
446+
} {
447+
mounted, err := Mounted(path)
448+
if err != nil || !mounted {
449+
t.Errorf("Mounted(%q): expected true, <nil>; got %v, %v", path, mounted, err)
450+
}
451+
452+
mounted, sure, err := MountedFast(path)
453+
if err != nil || !mounted || !sure {
454+
t.Errorf("MountedFast(%q): expected true, true, <nil>; got %v, %v, %v", path, mounted, sure, err)
455+
}
456+
}
457+
}

0 commit comments

Comments
 (0)