Skip to content

Commit 3ae6219

Browse files
committed
mountinfo/TestMountedBy*: add missing pre-checks
Both tests need (1) root (2) openat2. Do skip if those are not available. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent f84e14d commit 3ae6219

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mountinfo/mounted_linux_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,20 @@ func cleanupMounts(t *testing.T, dir string, mounts []string) {
174174
}
175175
}
176176

177-
func TestMountedBy(t *testing.T) {
177+
func requireOpenat2(t *testing.T) {
178+
t.Helper()
178179
if os.Getuid() != 0 {
179180
t.Skip("requires root")
180181
}
182+
fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY})
183+
if err != nil {
184+
t.Skipf("openat2: %v (old kernel? need Linux 5.6+)", err)
185+
}
186+
unix.Close(fd)
187+
}
188+
189+
func TestMountedBy(t *testing.T) {
190+
requireOpenat2(t)
181191

182192
dir, mounts, err := prepareMounts(t)
183193
defer cleanupMounts(t, dir, mounts)
@@ -224,11 +234,7 @@ func TestMountedBy(t *testing.T) {
224234
}
225235

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

233239
mounts, err := GetMounts(nil)
234240
if err != nil {

0 commit comments

Comments
 (0)