diff --git a/cri/v1alpha1/cri_utils_test.go b/cri/v1alpha1/cri_utils_test.go index 2a72fb035..9a2ed0e5a 100644 --- a/cri/v1alpha1/cri_utils_test.go +++ b/cri/v1alpha1/cri_utils_test.go @@ -3,6 +3,7 @@ package v1alpha1 import ( "fmt" "reflect" + "sort" "strings" "testing" @@ -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) { @@ -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) }