Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit-test for getSELinuxSecurityOpts method which locate on cri/v… #2023

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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