@@ -35,12 +35,6 @@ import (
35
35
const testNamespaceOne = "test-namespace-1"
36
36
const testNamespaceTwo = "test-namespace-2"
37
37
38
- var informerCache cache.Cache
39
- var stop chan struct {}
40
- var knownPod1 runtime.Object
41
- var knownPod2 runtime.Object
42
- var knownPod3 runtime.Object
43
-
44
38
func createPod (name , namespace string , restartPolicy kcorev1.RestartPolicy ) runtime.Object {
45
39
three := int64 (3 )
46
40
pod := & kcorev1.Pod {
@@ -59,20 +53,28 @@ func createPod(name, namespace string, restartPolicy kcorev1.RestartPolicy) runt
59
53
}
60
54
cl , err := client .New (cfg , client.Options {})
61
55
Expect (err ).NotTo (HaveOccurred ())
62
- err = cl .Create (context .TODO (), pod )
56
+ err = cl .Create (context .Background (), pod )
63
57
Expect (err ).NotTo (HaveOccurred ())
64
58
return pod
65
59
}
66
60
67
61
func deletePod (pod runtime.Object ) {
68
62
cl , err := client .New (cfg , client.Options {})
69
63
Expect (err ).NotTo (HaveOccurred ())
70
- err = cl .Delete (context .TODO (), pod )
64
+ err = cl .Delete (context .Background (), pod )
71
65
Expect (err ).NotTo (HaveOccurred ())
72
66
}
73
67
74
68
var _ = Describe ("Informer Cache" , func () {
75
69
70
+ var (
71
+ informerCache cache.Cache
72
+ stop chan struct {}
73
+ knownPod1 runtime.Object
74
+ knownPod2 runtime.Object
75
+ knownPod3 runtime.Object
76
+ )
77
+
76
78
BeforeEach (func () {
77
79
stop = make (chan struct {})
78
80
Expect (cfg ).NotTo (BeNil ())
@@ -137,12 +139,12 @@ var _ = Describe("Informer Cache", func() {
137
139
By ("listing pods with a particular label" )
138
140
// NB: each pod has a "test-label" equal to the pod name
139
141
out := kcorev1.PodList {}
140
- Expect (informerCache .List (context .TODO (), client .InNamespace (testNamespaceTwo ).
142
+ Expect (informerCache .List (context .Background (), client .InNamespace (testNamespaceTwo ).
141
143
MatchingLabels (map [string ]string {"test-label" : "test-pod-2" }), & out )).NotTo (HaveOccurred ())
142
144
143
145
By ("verifying the returned pods have the correct label" )
144
146
Expect (out .Items ).NotTo (BeEmpty ())
145
- Expect (len ( out .Items )). To ( Equal (1 ))
147
+ Expect (out .Items ). Should ( HaveLen (1 ))
146
148
actual := out .Items [0 ]
147
149
Expect (actual .Labels ["test-label" ]).To (Equal ("test-pod-2" ))
148
150
})
@@ -156,7 +158,7 @@ var _ = Describe("Informer Cache", func() {
156
158
157
159
By ("verifying that the returned pods are in test-namespace-1" )
158
160
Expect (listObj .Items ).NotTo (BeEmpty ())
159
- Expect (len ( listObj .Items )). To ( Equal (1 ))
161
+ Expect (listObj .Items ). Should ( HaveLen (1 ))
160
162
actual := listObj .Items [0 ]
161
163
Expect (actual .Namespace ).To (Equal (testNamespaceOne ))
162
164
})
@@ -185,7 +187,7 @@ var _ = Describe("Informer Cache", func() {
185
187
By ("verifying that an error is returned" )
186
188
err := informerCache .Get (context .Background (), svcKey , svc )
187
189
Expect (err ).To (HaveOccurred ())
188
- Expect (errors .IsNotFound (err )).To (Equal ( true ))
190
+ Expect (errors .IsNotFound (err )).To (BeTrue ( ))
189
191
})
190
192
})
191
193
@@ -209,7 +211,7 @@ var _ = Describe("Informer Cache", func() {
209
211
sii , err := informerCache .GetInformer (pod )
210
212
Expect (err ).NotTo (HaveOccurred ())
211
213
Expect (sii ).NotTo (BeNil ())
212
- Expect (sii .HasSynced ()).To (Equal ( true ))
214
+ Expect (sii .HasSynced ()).To (BeTrue ( ))
213
215
214
216
By ("adding an event handler listening for object creation which sends the object to a channel" )
215
217
out := make (chan interface {})
@@ -221,7 +223,7 @@ var _ = Describe("Informer Cache", func() {
221
223
By ("adding an object" )
222
224
cl , err := client .New (cfg , client.Options {})
223
225
Expect (err ).NotTo (HaveOccurred ())
224
- Expect (cl .Create (context .TODO (), pod )).To (Succeed ())
226
+ Expect (cl .Create (context .Background (), pod )).To (Succeed ())
225
227
226
228
By ("verifying the object is received on the channel" )
227
229
Eventually (out ).Should (Receive (Equal (pod )))
@@ -234,7 +236,7 @@ var _ = Describe("Informer Cache", func() {
234
236
sii , err := informerCache .GetInformerForKind (gvk )
235
237
Expect (err ).NotTo (HaveOccurred ())
236
238
Expect (sii ).NotTo (BeNil ())
237
- Expect (sii .HasSynced ()).To (Equal ( true ))
239
+ Expect (sii .HasSynced ()).To (BeTrue ( ))
238
240
239
241
By ("adding an event handler listening for object creation which sends the object to a channel" )
240
242
out := make (chan interface {})
@@ -260,7 +262,7 @@ var _ = Describe("Informer Cache", func() {
260
262
},
261
263
},
262
264
}
263
- Expect (cl .Create (context .TODO (), pod )).To (Succeed ())
265
+ Expect (cl .Create (context .Background (), pod )).To (Succeed ())
264
266
265
267
By ("verifying the object is received on the channel" )
266
268
Eventually (out ).Should (Receive (Equal (pod )))
@@ -294,7 +296,7 @@ var _ = Describe("Informer Cache", func() {
294
296
295
297
By ("verifying that the returned pods have correct restart policy" )
296
298
Expect (listObj .Items ).NotTo (BeEmpty ())
297
- Expect (len ( listObj .Items )). To ( Equal (1 ))
299
+ Expect (listObj .Items ). Should ( HaveLen (1 ))
298
300
actual := listObj .Items [0 ]
299
301
Expect (actual .Name ).To (Equal ("test-pod-3" ))
300
302
})
0 commit comments