Skip to content

Commit 098ed00

Browse files
committed
mountinfo: TestMountedBy: skip mountedByOpenat2() check if not supported
This updates the test to only skip the mountedByOpenat2() part, instead of skipping the whole test, if openat2 is not supported. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 76a42cd commit 098ed00

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

mountinfo/mounted_linux_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,27 @@ func requireOpenat2(t *testing.T) {
179179
if os.Getuid() != 0 {
180180
t.Skip("requires root")
181181
}
182-
fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY})
183-
if err != nil {
182+
if err := tryOpenat2(); err != nil {
184183
t.Skipf("openat2: %v (old kernel? need Linux 5.6+)", err)
185184
}
186-
unix.Close(fd)
187185
}
188186

189-
func TestMountedBy(t *testing.T) {
190-
requireOpenat2(t)
187+
func tryOpenat2() error {
188+
fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY})
189+
if err == nil {
190+
_ = unix.Close(fd)
191+
}
192+
return err
193+
}
191194

195+
func TestMountedBy(t *testing.T) {
192196
dir, mounts, err := prepareMounts(t)
193197
defer cleanupMounts(t, dir, mounts)
194198
if err != nil {
195199
t.Fatalf("setup failed: %v", err)
196200
}
197201

202+
openat2Supported := tryOpenat2() == nil
198203
checked := false
199204
for _, m := range mounts {
200205
exp := !strings.Contains(m, notMounted)
@@ -207,11 +212,14 @@ func TestMountedBy(t *testing.T) {
207212
}
208213

209214
checked = true
210-
mounted, err = mountedByOpenat2(m)
211-
if err != nil {
212-
t.Errorf("mountedByOpenat2(%q) error: %v", m, err)
213-
} else if mounted != exp {
214-
t.Errorf("mountedByOpenat2(%q): expected %v, got %v", m, exp, mounted)
215+
216+
if openat2Supported {
217+
mounted, err = mountedByOpenat2(m)
218+
if err != nil {
219+
t.Errorf("mountedByOpenat2(%q) error: %v", m, err)
220+
} else if mounted != exp {
221+
t.Errorf("mountedByOpenat2(%q): expected %v, got %v", m, exp, mounted)
222+
}
215223
}
216224

217225
mounted, err = mountedByStat(m)

0 commit comments

Comments
 (0)