Skip to content

Commit

Permalink
mountinfo/TestMountedBy*: add missing pre-checks
Browse files Browse the repository at this point in the history
Both tests need (1) root (2) openat2.

Do skip if those are not available.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Feb 17, 2021
1 parent f4a20b4 commit 17f05a2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mountinfo/mounted_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,20 @@ func cleanupMounts(t *testing.T, dir string, mounts []string) {
}
}

func TestMountedBy(t *testing.T) {
func requireOpenat2(t *testing.T) {
t.Helper()
if os.Getuid() != 0 {
t.Skip("requires root")
}
fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY})
if err != nil {
t.Skipf("openat2: %v (old kernel? need Linux 5.6+)", err)
}
unix.Close(fd)
}

func TestMountedBy(t *testing.T) {
requireOpenat2(t)

dir, mounts, err := prepareMounts(t)
defer cleanupMounts(t, dir, mounts)
Expand Down Expand Up @@ -224,11 +234,7 @@ func TestMountedBy(t *testing.T) {
}

func TestMountedByOpenat2VsMountinfo(t *testing.T) {
fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY})
if err != nil {
t.Skipf("openat2: %v (old kernel? need Linux 5.6+)", err)
}
unix.Close(fd)
requireOpenat2(t)

mounts, err := GetMounts(nil)
if err != nil {
Expand Down

0 comments on commit 17f05a2

Please sign in to comment.