Skip to content

Commit 5ac77ed

Browse files
committed
libct/int: add/use needUserNS helper
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 67edd6d commit 5ac77ed

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

libcontainer/integration/exec_test.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package integration
33
import (
44
"bytes"
55
"encoding/json"
6-
"errors"
76
"fmt"
87
"os"
98
"os/exec"
@@ -30,9 +29,7 @@ func TestExecPS(t *testing.T) {
3029
}
3130

3231
func TestUsernsExecPS(t *testing.T) {
33-
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
34-
t.Skip("Test requires userns.")
35-
}
32+
needUserNS(t)
3633
testExecPS(t, true)
3734
}
3835

@@ -122,10 +119,7 @@ func TestRlimit(t *testing.T) {
122119
}
123120

124121
func TestUsernsRlimit(t *testing.T) {
125-
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
126-
t.Skip("Test requires userns.")
127-
}
128-
122+
needUserNS(t)
129123
testRlimit(t, true)
130124
}
131125

@@ -1515,9 +1509,7 @@ func TestInitJoinPID(t *testing.T) {
15151509
}
15161510

15171511
func TestInitJoinNetworkAndUser(t *testing.T) {
1518-
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
1519-
t.Skip("Test requires userns.")
1520-
}
1512+
needUserNS(t)
15211513
if testing.Short() {
15221514
return
15231515
}
@@ -1764,10 +1756,7 @@ next_fd:
17641756
// Test that a container using user namespaces is able to bind mount a folder
17651757
// that does not have permissions for group/others.
17661758
func TestBindMountAndUser(t *testing.T) {
1767-
if _, err := os.Stat("/proc/self/ns/user"); errors.Is(err, os.ErrNotExist) {
1768-
t.Skip("userns is unsupported")
1769-
}
1770-
1759+
needUserNS(t)
17711760
if testing.Short() {
17721761
return
17731762
}

libcontainer/integration/execin_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func TestExecIn(t *testing.T) {
6969
}
7070

7171
func TestExecInUsernsRlimit(t *testing.T) {
72-
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
73-
t.Skip("Test requires userns.")
74-
}
75-
72+
needUserNS(t)
7673
testExecInRlimit(t, true)
7774
}
7875

@@ -502,9 +499,7 @@ func TestExecInOomScoreAdj(t *testing.T) {
502499
}
503500

504501
func TestExecInUserns(t *testing.T) {
505-
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
506-
t.Skip("Test requires userns.")
507-
}
502+
needUserNS(t)
508503
if testing.Short() {
509504
return
510505
}

libcontainer/integration/utils_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"os"
78
"os/exec"
@@ -231,3 +232,10 @@ func runContainerOk(t testing.TB, config *configs.Config, args ...string) *stdBu
231232
func destroyContainer(container *libcontainer.Container) {
232233
_ = container.Destroy()
233234
}
235+
236+
func needUserNS(t testing.TB) {
237+
t.Helper()
238+
if _, err := os.Stat("/proc/self/ns/user"); errors.Is(err, os.ErrNotExist) {
239+
t.Skip("Test requires userns.")
240+
}
241+
}

0 commit comments

Comments
 (0)