Skip to content

Commit

Permalink
Merge pull request #2023 from Coordinate36/dev1
Browse files Browse the repository at this point in the history
test: add unit-test for getSELinuxSecurityOpts method which locate on cri/v…
  • Loading branch information
allencloud authored Aug 1, 2018
2 parents 5fab7cc + 109af10 commit a8b6b19
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cri/v1alpha1/cri_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ import (
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

func Test_getSELinuxSecurityOpts(t *testing.T) {
type args struct {
sc *runtime.LinuxContainerSecurityContext
}
tests := []struct {
name string
args args
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},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getSELinuxSecurityOpts(tt.args.sc)
if (err != nil) != tt.wantErr {
t.Errorf("getSELinuxSecurityOpts() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("getSELinuxSecurityOpts() = %v, want %v", got, tt.want)
}
})
}
}

func Test_parseUint32(t *testing.T) {
type args struct {
s string
Expand Down

0 comments on commit a8b6b19

Please sign in to comment.