Skip to content

Commit

Permalink
Merge pull request #2031 from Starnop/cri-test-getSELinuxSecurityOpts
Browse files Browse the repository at this point in the history
bugfix: cri Test_getSELinuxSecurityOpts
  • Loading branch information
Wei Fu authored Aug 1, 2018
2 parents 5ed312e + 725db37 commit 6b31add
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cri/v1alpha1/cri_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1alpha1
import (
"fmt"
"reflect"
"sort"
"strings"
"testing"

Expand All @@ -24,11 +25,11 @@ func Test_getSELinuxSecurityOpts(t *testing.T) {
want []string
wantErr bool
}{
{"test1", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "", Role: "", Type: "", Level: ""}}}, nil, false},
{"test2", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "xzx", Role: "", Type: "", Level: ""}}}, nil, false},
{"test3", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "xzx", Role: "xzx", Type: "", Level: ""}}}, nil, false},
{"test4", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "xzx", Role: "xzx", Type: "xzx", Level: ""}}}, nil, false},
{"test5", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "xzx", Role: "xzx", Type: "xzx", Level: "xzx"}}}, []string{"label=user:xzx", "label=role:xzx", "label=type:xzx", "label=level:xzx"}, false},
{"All Empty Test", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "", Role: "", Type: "", Level: ""}}}, nil, false},
{"User Not Empty Test", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "foo", Role: "", Type: "", Level: ""}}}, nil, false},
{"Type And Level Empty Test", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "foo", Role: "foo", Type: "", Level: ""}}}, nil, false},
{"Level Empty Test", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "foo", Role: "foo", Type: "foo", Level: ""}}}, nil, false},
{"All Not Empty Test", args{&runtime.LinuxContainerSecurityContext{SelinuxOptions: &runtime.SELinuxOption{User: "foo", Role: "foo", Type: "foo", Level: "foo"}}}, []string{"label=user:foo", "label=role:foo", "label=type:foo", "label=level:foo"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -37,6 +38,8 @@ func Test_getSELinuxSecurityOpts(t *testing.T) {
t.Errorf("getSELinuxSecurityOpts() error = %v, wantErr %v", err, tt.wantErr)
return
}
sort.Strings(got)
sort.Strings(tt.want)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("getSELinuxSecurityOpts() = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 6b31add

Please sign in to comment.