test: add test case for create service.

This commit is contained in:
yunlzheng
2020-03-13 13:11:44 +08:00
parent 6273005d06
commit 84b4f135bd
+39
View File
@@ -129,3 +129,42 @@ func TestKubernetes_ClusterCrids(t *testing.T) {
})
}
}
func TestKubernetes_CreateService(t *testing.T) {
type args struct {
name string
namespace string
port int
labels map[string]string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "shouldCreateService",
args: args{
name: "svc-name",
namespace: "default",
port: 8080,
labels: map[string]string{
"label": "value",
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
k := &Kubernetes{
Clientset: testclient.NewSimpleClientset(),
}
_, err := k.CreateService(tt.args.name, tt.args.namespace, tt.args.port, tt.args.labels)
if (err != nil) != tt.wantErr {
t.Errorf("Kubernetes.CreateService() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}