forked from tcfw/go-grpc-k8s-resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s_test.go
61 lines (55 loc) · 1.19 KB
/
k8s_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
package k8sresolver
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
)
func TestResolve(t *testing.T) {
s := serviceClient{
namespace: "default",
k8s: fake.NewSimpleClientset(
&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
Annotations: map[string]string{},
},
Subsets: []v1.EndpointSubset{
{
Addresses: []v1.EndpointAddress{
{IP: "1.1.1.1"},
},
},
}},
),
}
res, err := s.Resolve(context.Background(), "test", "0")
if assert.NoError(t, err) {
assert.Equal(t, []string{"1.1.1.1:0"}, res)
}
}
func TestWatch(t *testing.T) {
s := serviceClient{
namespace: "default",
k8s: fake.NewSimpleClientset(
&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
Annotations: map[string]string{},
},
Subsets: []v1.EndpointSubset{
{
Addresses: []v1.EndpointAddress{
{IP: "1.1.1.1"},
},
},
}},
),
}
_, _, err := s.Watch(context.Background(), "test")
assert.NoError(t, err)
}