Skip to content

Commit

Permalink
add testing cri_utils_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mangodai authored Jul 31, 2018
1 parent e42ceba commit 4ddb98a
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions cri/v1alpha1/cri_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,80 @@ import (
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)


func Test_getSELinuxSecurityOpts(t *testing.T) {
var (
nilContext = runtime.LinuxContainerSecurityContext{
SelinuxOptions: &runtime.SELinuxOption{
User: "",
Role: "",
Type: "",
Level: "",
},
}
halfContext = runtime.LinuxContainerSecurityContext{
SelinuxOptions: &runtime.SELinuxOption{
User: "zs",
Role: "user",
},
}
normalContext = runtime.LinuxContainerSecurityContext{
SelinuxOptions: &runtime.SELinuxOption{
User: "zs",
Role: "user",
Type: "type1",
Level: "1",
},
}
)
type args struct {
sc *runtime.LinuxContainerSecurityContext
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "nil test",
args: args{
sc: &nilContext,
},
want: nil,
wantErr: false,
},
{
name: "harf test",
args: args{
sc: &halfContext,
},
want: []string{"label=user:zs", "label=role:user"},
wantErr: false,
},
{
name: "normal content",
args: args{
sc: &normalContext,
},
want: []string{"label=user:zs", "label=role:user", "label=type:type1", "label=level:1"},
wantErr: 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 4ddb98a

Please sign in to comment.