diff --git a/cri/v1alpha1/cri_utils_test.go b/cri/v1alpha1/cri_utils_test.go index 01f39c393..b0c4eadf1 100644 --- a/cri/v1alpha1/cri_utils_test.go +++ b/cri/v1alpha1/cri_utils_test.go @@ -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