@@ -31,6 +31,9 @@ import (
31
31
"sigs.k8s.io/controller-runtime/pkg/client"
32
32
)
33
33
34
+ const testNamespaceOne = "test-namespace-1"
35
+ const testNamespaceTwo = "test-namespace-2"
36
+
34
37
var informerCache cache.Cache
35
38
var stop chan struct {}
36
39
var knownPod1 runtime.Object
@@ -74,9 +77,9 @@ var _ = Describe("Informer Cache", func() {
74
77
Expect (cfg ).NotTo (BeNil ())
75
78
76
79
By ("creating three pods" )
77
- knownPod1 = createPod ("test-pod-1" , "test-namespace-1" , kcorev1 .RestartPolicyNever )
78
- knownPod2 = createPod ("test-pod-2" , "test-namespace-2" , kcorev1 .RestartPolicyAlways )
79
- knownPod3 = createPod ("test-pod-3" , "test-namespace-2" , kcorev1 .RestartPolicyOnFailure )
80
+ knownPod1 = createPod ("test-pod-1" , testNamespaceOne , kcorev1 .RestartPolicyNever )
81
+ knownPod2 = createPod ("test-pod-2" , testNamespaceTwo , kcorev1 .RestartPolicyAlways )
82
+ knownPod3 = createPod ("test-pod-3" , testNamespaceTwo , kcorev1 .RestartPolicyOnFailure )
80
83
81
84
By ("creating the informer cache" )
82
85
var err error
@@ -135,7 +138,7 @@ var _ = Describe("Informer Cache", func() {
135
138
By ("listing pods with a particular label" )
136
139
// NB: each pod has a "test-label" equal to the pod name
137
140
out := kcorev1.PodList {}
138
- Expect (informerCache .List (context .TODO (), client .InNamespace ("test-namespace-2" ).
141
+ Expect (informerCache .List (context .TODO (), client .InNamespace (testNamespaceTwo ).
139
142
MatchingLabels (map [string ]string {"test-label" : "test-pod-2" }), & out )).NotTo (HaveOccurred ())
140
143
141
144
By ("verifying the returned pods have the correct label" )
@@ -150,21 +153,21 @@ var _ = Describe("Informer Cache", func() {
150
153
By ("listing pods in test-namespace-1" )
151
154
listObj := & kcorev1.PodList {}
152
155
Expect (informerCache .List (context .Background (),
153
- client .InNamespace ("test-namespace-1" ),
156
+ client .InNamespace (testNamespaceOne ),
154
157
listObj )).NotTo (HaveOccurred ())
155
158
156
159
By ("verifying that the returned pods are in test-namespace-1" )
157
160
Expect (listObj .Items ).NotTo (BeEmpty ())
158
161
Expect (len (listObj .Items )).To (Equal (1 ))
159
162
actual := listObj .Items [0 ]
160
- Expect (actual .Namespace ).To (Equal ("test-namespace-1" ))
163
+ Expect (actual .Namespace ).To (Equal (testNamespaceOne ))
161
164
close (done )
162
165
})
163
166
164
167
It ("should deep copy the object unless told otherwise" , func (done Done ) {
165
168
By ("retrieving a specific pod from the cache" )
166
169
out := & kcorev1.Pod {}
167
- podKey := client.ObjectKey {Name : "test-pod-2" , Namespace : "test-namespace-2" }
170
+ podKey := client.ObjectKey {Name : "test-pod-2" , Namespace : testNamespaceTwo }
168
171
Expect (informerCache .Get (context .Background (), podKey , out )).NotTo (HaveOccurred ())
169
172
170
173
By ("verifying the retrieved pod is equal to a known pod" )
0 commit comments