forked from nginx/nginx-gateway-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpointslice_test.go
58 lines (52 loc) · 1.16 KB
/
endpointslice_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
package index
import (
"testing"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
discoveryV1 "k8s.io/api/discovery/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func TestServiceNameIndexFunc(t *testing.T) {
testcases := []struct {
msg string
obj client.Object
expOutput []string
}{
{
msg: "normal case",
obj: &discoveryV1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{KubernetesServiceNameLabel: "test-svc"},
},
},
expOutput: []string{"test-svc"},
},
{
msg: "nil labels",
obj: &discoveryV1.EndpointSlice{},
expOutput: nil,
},
{
msg: "no service-name label",
obj: &discoveryV1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Labels: make(map[string]string),
},
},
expOutput: nil,
},
}
for _, tc := range testcases {
g := NewWithT(t)
output := ServiceNameIndexFunc(tc.obj)
g.Expect(output).To(Equal(tc.expOutput))
}
}
func TestServiceNameIndexFuncPanics(t *testing.T) {
defer func() {
g := NewWithT(t)
g.Expect(recover()).ToNot(BeNil())
}()
ServiceNameIndexFunc(&v1.Namespace{})
}