-
Notifications
You must be signed in to change notification settings - Fork 5
/
kubernetes_test.go
62 lines (55 loc) · 1.13 KB
/
kubernetes_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
package pprofserver
import (
"context"
"testing"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
)
func makePod() *v1.Pod {
return &v1.Pod{
Spec: v1.PodSpec{
NodeName: "instance0",
Containers: []v1.Container{
{
Name: "container0",
Ports: []v1.ContainerPort{
{
Name: "http",
Protocol: v1.ProtocolTCP,
ContainerPort: int32(3000),
},
},
},
},
},
Status: v1.PodStatus{
PodIP: "1.2.3.4",
HostIP: "1.2.3.5",
},
}
}
func kubernetesRegistryWith(objects ...runtime.Object) *KubernetesRegistry {
return &KubernetesRegistry{
client: fake.NewSimpleClientset(objects...),
}
}
func TestKubernetesRegistry(t *testing.T) {
ctx := context.TODO()
tests := []struct {
scenario string
objects []runtime.Object
}{
{"single valid pod", []runtime.Object{makePod()}},
}
for _, test := range tests {
t.Run(test.scenario, func(t *testing.T) {
registry := kubernetesRegistryWith(test.objects...)
registry.Init(ctx)
_, err := registry.LookupService(ctx, "")
if err != nil {
t.Error(err)
}
})
}
}