Skip to content

Commit 538cfc5

Browse files
committed
Addressed comments from Solly
1 parent 6a88ad1 commit 538cfc5

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

pkg/cache/cache_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ import (
3535
const testNamespaceOne = "test-namespace-1"
3636
const testNamespaceTwo = "test-namespace-2"
3737

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-
4438
func createPod(name, namespace string, restartPolicy kcorev1.RestartPolicy) runtime.Object {
4539
three := int64(3)
4640
pod := &kcorev1.Pod{
@@ -59,20 +53,28 @@ func createPod(name, namespace string, restartPolicy kcorev1.RestartPolicy) runt
5953
}
6054
cl, err := client.New(cfg, client.Options{})
6155
Expect(err).NotTo(HaveOccurred())
62-
err = cl.Create(context.TODO(), pod)
56+
err = cl.Create(context.Background(), pod)
6357
Expect(err).NotTo(HaveOccurred())
6458
return pod
6559
}
6660

6761
func deletePod(pod runtime.Object) {
6862
cl, err := client.New(cfg, client.Options{})
6963
Expect(err).NotTo(HaveOccurred())
70-
err = cl.Delete(context.TODO(), pod)
64+
err = cl.Delete(context.Background(), pod)
7165
Expect(err).NotTo(HaveOccurred())
7266
}
7367

7468
var _ = Describe("Informer Cache", func() {
7569

70+
var (
71+
informerCache cache.Cache
72+
stop chan struct{}
73+
knownPod1 runtime.Object
74+
knownPod2 runtime.Object
75+
knownPod3 runtime.Object
76+
)
77+
7678
BeforeEach(func() {
7779
stop = make(chan struct{})
7880
Expect(cfg).NotTo(BeNil())
@@ -137,12 +139,12 @@ var _ = Describe("Informer Cache", func() {
137139
By("listing pods with a particular label")
138140
// NB: each pod has a "test-label" equal to the pod name
139141
out := kcorev1.PodList{}
140-
Expect(informerCache.List(context.TODO(), client.InNamespace(testNamespaceTwo).
142+
Expect(informerCache.List(context.Background(), client.InNamespace(testNamespaceTwo).
141143
MatchingLabels(map[string]string{"test-label": "test-pod-2"}), &out)).NotTo(HaveOccurred())
142144

143145
By("verifying the returned pods have the correct label")
144146
Expect(out.Items).NotTo(BeEmpty())
145-
Expect(len(out.Items)).To(Equal(1))
147+
Expect(out.Items).Should(HaveLen(1))
146148
actual := out.Items[0]
147149
Expect(actual.Labels["test-label"]).To(Equal("test-pod-2"))
148150
})
@@ -156,7 +158,7 @@ var _ = Describe("Informer Cache", func() {
156158

157159
By("verifying that the returned pods are in test-namespace-1")
158160
Expect(listObj.Items).NotTo(BeEmpty())
159-
Expect(len(listObj.Items)).To(Equal(1))
161+
Expect(listObj.Items).Should(HaveLen(1))
160162
actual := listObj.Items[0]
161163
Expect(actual.Namespace).To(Equal(testNamespaceOne))
162164
})
@@ -185,7 +187,7 @@ var _ = Describe("Informer Cache", func() {
185187
By("verifying that an error is returned")
186188
err := informerCache.Get(context.Background(), svcKey, svc)
187189
Expect(err).To(HaveOccurred())
188-
Expect(errors.IsNotFound(err)).To(Equal(true))
190+
Expect(errors.IsNotFound(err)).To(BeTrue())
189191
})
190192
})
191193

@@ -209,7 +211,7 @@ var _ = Describe("Informer Cache", func() {
209211
sii, err := informerCache.GetInformer(pod)
210212
Expect(err).NotTo(HaveOccurred())
211213
Expect(sii).NotTo(BeNil())
212-
Expect(sii.HasSynced()).To(Equal(true))
214+
Expect(sii.HasSynced()).To(BeTrue())
213215

214216
By("adding an event handler listening for object creation which sends the object to a channel")
215217
out := make(chan interface{})
@@ -221,7 +223,7 @@ var _ = Describe("Informer Cache", func() {
221223
By("adding an object")
222224
cl, err := client.New(cfg, client.Options{})
223225
Expect(err).NotTo(HaveOccurred())
224-
Expect(cl.Create(context.TODO(), pod)).To(Succeed())
226+
Expect(cl.Create(context.Background(), pod)).To(Succeed())
225227

226228
By("verifying the object is received on the channel")
227229
Eventually(out).Should(Receive(Equal(pod)))
@@ -234,7 +236,7 @@ var _ = Describe("Informer Cache", func() {
234236
sii, err := informerCache.GetInformerForKind(gvk)
235237
Expect(err).NotTo(HaveOccurred())
236238
Expect(sii).NotTo(BeNil())
237-
Expect(sii.HasSynced()).To(Equal(true))
239+
Expect(sii.HasSynced()).To(BeTrue())
238240

239241
By("adding an event handler listening for object creation which sends the object to a channel")
240242
out := make(chan interface{})
@@ -260,7 +262,7 @@ var _ = Describe("Informer Cache", func() {
260262
},
261263
},
262264
}
263-
Expect(cl.Create(context.TODO(), pod)).To(Succeed())
265+
Expect(cl.Create(context.Background(), pod)).To(Succeed())
264266

265267
By("verifying the object is received on the channel")
266268
Eventually(out).Should(Receive(Equal(pod)))
@@ -294,7 +296,7 @@ var _ = Describe("Informer Cache", func() {
294296

295297
By("verifying that the returned pods have correct restart policy")
296298
Expect(listObj.Items).NotTo(BeEmpty())
297-
Expect(len(listObj.Items)).To(Equal(1))
299+
Expect(listObj.Items).Should(HaveLen(1))
298300
actual := listObj.Items[0]
299301
Expect(actual.Name).To(Equal("test-pod-3"))
300302
})

0 commit comments

Comments
 (0)