-
Notifications
You must be signed in to change notification settings - Fork 5
/
client_test.go
47 lines (36 loc) · 1.1 KB
/
client_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
package main
import (
"k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/controller/testutil"
"github.com/stretchr/testify/require"
"testing"
)
func TestClientGetPodsDirectly(t *testing.T) {
testClientGetPods(t, false)
}
func TestClientGetPodsUsingInformer(t *testing.T) {
testClientGetPods(t, true)
}
func testClientGetPods(t *testing.T, useInformer bool) {
pod := testutil.NewPod("pod1", "host1")
pod.ObjectMeta.Labels = make(map[string]string)
pod.ObjectMeta.Labels["name"] = "pod1"
fakeClient := fake.NewSimpleClientset(pod)
stopCh := make(chan struct{})
defer close(stopCh)
tc, err := newClient(fakeClient, stopCh, useInformer)
require.NoError(t, err)
pods, err := tc.Pods("", "")
require.NoError(t, err)
require.Len(t, pods, 1)
require.Equal(t, "pod1", pods[0].Name)
require.Equal(t, "host1", pods[0].Spec.NodeName)
pods, err = tc.Pods("", "name=unknown")
require.NoError(t, err)
require.Empty(t, pods)
pods, err = tc.Pods("", "name=pod1")
require.NoError(t, err)
require.Len(t, pods, 1)
require.Equal(t, "pod1", pods[0].Name)
require.Equal(t, "host1", pods[0].Spec.NodeName)
}