-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice_test.go
70 lines (61 loc) · 1.79 KB
/
service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package kube
import (
"context"
"testing"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func TestClientService(t *testing.T) {
var mockserviceport int32 = 8001
mockservicename := "mockservice"
mockservicenamespace := "default"
mockserviceportname := "mockportname"
mocksvc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: mockservicename,
Namespace: mockservicenamespace,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: mockserviceportname,
Port: mockserviceport,
TargetPort: intstr.IntOrString{
IntVal: mockserviceport,
},
}},
},
}
// clean
if _, err := mockcli.GetService(context.TODO(), mockservicenamespace, mockservicename); err == nil {
err := mockcli.DeleteService(context.TODO(), mockservicenamespace, mockservicename)
require.NoError(t, err)
}
t.Run("create:service", func(t *testing.T) {
svc := mocksvc
_, err := mockcli.CreateService(context.TODO(), svc)
require.NoError(t, err)
})
t.Run("create:service:error", func(t *testing.T) {
svc := mocksvc
svc.Namespace = ""
_, err := mockcli.CreateService(context.TODO(), svc)
require.EqualError(t, err, ErrorMissingNamespace.Error())
})
t.Run("get:service", func(t *testing.T) {
_, err := mockcli.GetService(context.TODO(), mockservicenamespace, mockservicename)
require.NoError(t, err)
})
t.Run("get:service:list", func(t *testing.T) {
list, err := mockcli.GetServices(context.TODO(), mockservicenamespace)
require.NoError(t, err)
if len(list.Items) == 0 {
t.Fatal(err)
}
})
t.Run("delete:service", func(t *testing.T) {
err := mockcli.DeleteService(context.TODO(), mockservicenamespace, mockservicename)
require.NoError(t, err)
})
}