Merge pull request #36750 from kolyshkin/t-mount-seclabel

pkg/mount/TestMount: fix wrt selinux
This commit is contained in:
Vincent Demeester 2018-05-23 15:22:37 +02:00 committed by GitHub
commit 0846a02d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 14 deletions

View File

@ -8,8 +8,6 @@ import (
"os"
"strings"
"testing"
selinux "github.com/opencontainers/selinux/go-selinux"
)
func TestMount(t *testing.T) {
@ -103,11 +101,7 @@ func TestMount(t *testing.T) {
t.Fatal(err)
}
defer ensureUnmount(t, target)
expectedVFS := tc.expectedVFS
if selinux.GetEnabled() && expectedVFS != "" {
expectedVFS = expectedVFS + ",seclabel"
}
validateMount(t, target, tc.expectedOpts, tc.expectedOptional, expectedVFS)
validateMount(t, target, tc.expectedOpts, tc.expectedOptional, tc.expectedVFS)
})
}
}
@ -177,13 +171,13 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
for _, opt := range strings.Split(mi.Opts, ",") {
opt = clean(opt)
if !has(wantedOpts, opt) && !has(pOpts, opt) {
t.Errorf("unexpected mount option %q expected %q", opt, opts)
t.Errorf("unexpected mount option %q, expected %q", opt, opts)
}
delete(wantedOpts, opt)
}
}
for opt := range wantedOpts {
t.Errorf("missing mount option %q found %q", opt, mi.Opts)
t.Errorf("missing mount option %q, found %q", opt, mi.Opts)
}
// Validate Optional
@ -191,13 +185,13 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
for _, field := range strings.Split(mi.Optional, ",") {
field = clean(field)
if !has(wantedOptional, field) && !has(pOptional, field) {
t.Errorf("unexpected optional failed %q expected %q", field, optional)
t.Errorf("unexpected optional field %q, expected %q", field, optional)
}
delete(wantedOptional, field)
}
}
for field := range wantedOptional {
t.Errorf("missing optional field %q found %q", field, mi.Optional)
t.Errorf("missing optional field %q, found %q", field, mi.Optional)
}
// Validate VFS if set
@ -205,14 +199,14 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
if mi.VfsOpts != "" {
for _, opt := range strings.Split(mi.VfsOpts, ",") {
opt = clean(opt)
if !has(wantedVFS, opt) {
t.Errorf("unexpected mount option %q expected %q", opt, vfs)
if !has(wantedVFS, opt) && opt != "seclabel" { // can be added by selinux
t.Errorf("unexpected vfs option %q, expected %q", opt, vfs)
}
delete(wantedVFS, opt)
}
}
for opt := range wantedVFS {
t.Errorf("missing mount option %q found %q", opt, mi.VfsOpts)
t.Errorf("missing vfs option %q, found %q", opt, mi.VfsOpts)
}
}