Skip to content

Commit e30672b

Browse files
committed
label_test: use t.Skip
When selinux is not supported, instead of silently retrurning from the test, use t.Skip() so that a user will know the test was skipped (and why) not passed as they would assume. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent e1f380a commit e30672b

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

go-selinux/label/label_linux_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import (
99
"github.com/opencontainers/selinux/go-selinux"
1010
)
1111

12-
func TestInit(t *testing.T) {
12+
func needSELinux(t *testing.T) {
13+
t.Helper()
1314
if !selinux.GetEnabled() {
14-
return
15+
t.Skip("SELinux not enabled, skipping.")
1516
}
17+
}
18+
19+
func TestInit(t *testing.T) {
20+
needSELinux(t)
21+
1622
var testNull []string
1723
_, _, err := InitLabels(testNull)
1824
if err != nil {
@@ -91,9 +97,8 @@ func TestDuplicateLabel(t *testing.T) {
9197
}
9298
}
9399
func TestRelabel(t *testing.T) {
94-
if !selinux.GetEnabled() {
95-
return
96-
}
100+
needSELinux(t)
101+
97102
testdir, err := ioutil.TempDir("/tmp", "")
98103
if err != nil {
99104
t.Fatal(err)
@@ -158,9 +163,8 @@ func TestIsShared(t *testing.T) {
158163
}
159164

160165
func TestSELinuxNoLevel(t *testing.T) {
161-
if !selinux.GetEnabled() {
162-
return
163-
}
166+
needSELinux(t)
167+
164168
tlabel := "system_u:system_r:container_t"
165169
dup, err := DupSecOpt(tlabel)
166170
if err != nil {
@@ -180,9 +184,8 @@ func TestSELinuxNoLevel(t *testing.T) {
180184
}
181185

182186
func TestSocketLabel(t *testing.T) {
183-
if !selinux.GetEnabled() {
184-
return
185-
}
187+
needSELinux(t)
188+
186189
label := "system_u:object_r:container_t:s0:c1,c2"
187190
if err := selinux.SetSocketLabel(label); err != nil {
188191
t.Fatal(err)
@@ -197,9 +200,8 @@ func TestSocketLabel(t *testing.T) {
197200
}
198201

199202
func TestKeyLabel(t *testing.T) {
200-
if !selinux.GetEnabled() {
201-
return
202-
}
203+
needSELinux(t)
204+
203205
label := "system_u:object_r:container_t:s0:c1,c2"
204206
if err := selinux.SetKeyLabel(label); err != nil {
205207
t.Fatal(err)
@@ -214,9 +216,8 @@ func TestKeyLabel(t *testing.T) {
214216
}
215217

216218
func TestFileLabel(t *testing.T) {
217-
if !selinux.GetEnabled() {
218-
return
219-
}
219+
needSELinux(t)
220+
220221
testUser := []string{"filetype:test_file_t", "level:s0:c1,c15"}
221222
_, mlabel, err := InitLabels(testUser)
222223
if err != nil {

0 commit comments

Comments
 (0)