Skip to content

Commit c205dab

Browse files
committed
Addressed review comments
1 parent a0cf870 commit c205dab

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

pkg/cache/cache_test.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
. "github.com/onsi/ginkgo"
2323
. "github.com/onsi/gomega"
2424
kcorev1 "k8s.io/api/core/v1"
25+
"k8s.io/apimachinery/pkg/api/errors"
2526
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/runtime"
2728
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -102,8 +103,8 @@ var _ = Describe("Informer Cache", func() {
102103
close(stop)
103104
})
104105

105-
Describe("Cache as a Reader", func() {
106-
It("should be able to list objects that haven't been watched previously", func(done Done) {
106+
Describe("as a Reader", func() {
107+
It("should be able to list objects that haven't been watched previously", func() {
107108
By("listing all services in the cluster")
108109
listObj := &kcorev1.ServiceList{}
109110
Expect(informerCache.List(context.Background(), nil, listObj)).NotTo(HaveOccurred())
@@ -119,10 +120,9 @@ var _ = Describe("Informer Cache", func() {
119120
}
120121
}
121122
Expect(hasKubeService).To(BeTrue())
122-
close(done)
123123
})
124124

125-
It("should be able to get objects that haven't been watched previously", func(done Done) {
125+
It("should be able to get objects that haven't been watched previously", func() {
126126
By("getting the Kubernetes service")
127127
svc := &kcorev1.Service{}
128128
svcKey := client.ObjectKey{Namespace: "default", Name: "kubernetes"}
@@ -131,10 +131,9 @@ var _ = Describe("Informer Cache", func() {
131131
By("verifying that the returned service looks reasonable")
132132
Expect(svc.Name).To(Equal("kubernetes"))
133133
Expect(svc.Namespace).To(Equal("default"))
134-
close(done)
135134
})
136135

137-
It("should support filtering by labels", func(done Done) {
136+
It("should support filtering by labels", func() {
138137
By("listing pods with a particular label")
139138
// NB: each pod has a "test-label" equal to the pod name
140139
out := kcorev1.PodList{}
@@ -146,10 +145,9 @@ var _ = Describe("Informer Cache", func() {
146145
Expect(len(out.Items)).To(Equal(1))
147146
actual := out.Items[0]
148147
Expect(actual.Labels["test-label"]).To(Equal("test-pod-2"))
149-
close(done)
150148
})
151149

152-
It("should be able to list objects by namespace", func(done Done) {
150+
It("should be able to list objects by namespace", func() {
153151
By("listing pods in test-namespace-1")
154152
listObj := &kcorev1.PodList{}
155153
Expect(informerCache.List(context.Background(),
@@ -161,10 +159,9 @@ var _ = Describe("Informer Cache", func() {
161159
Expect(len(listObj.Items)).To(Equal(1))
162160
actual := listObj.Items[0]
163161
Expect(actual.Namespace).To(Equal(testNamespaceOne))
164-
close(done)
165162
})
166163

167-
It("should deep copy the object unless told otherwise", func(done Done) {
164+
It("should deep copy the object unless told otherwise", func() {
168165
By("retrieving a specific pod from the cache")
169166
out := &kcorev1.Pod{}
170167
podKey := client.ObjectKey{Name: "test-pod-2", Namespace: testNamespaceTwo}
@@ -178,21 +175,21 @@ var _ = Describe("Informer Cache", func() {
178175

179176
By("verifying the pods are no longer equal")
180177
Expect(out).NotTo(Equal(knownPod2))
181-
close(done)
182178
})
183179

184-
It("should error out for missing objects", func(done Done) {
180+
It("should error out for missing objects", func() {
185181
By("getting a service that does not exists")
186182
svc := &kcorev1.Service{}
187183
svcKey := client.ObjectKey{Namespace: "unknown", Name: "unknown"}
188184

189185
By("verifying that an error is returned")
190-
Expect(informerCache.Get(context.Background(), svcKey, svc)).To(HaveOccurred())
191-
close(done)
186+
err := informerCache.Get(context.Background(), svcKey, svc)
187+
Expect(err).To(HaveOccurred())
188+
Expect(errors.IsNotFound(err)).To(Equal(true))
192189
})
193190
})
194191

195-
Describe("Cache as an Informer", func() {
192+
Describe("as an Informer", func() {
196193
It("should be able to get informer for the object", func(done Done) {
197194
By("getting an shared index informer for a pod")
198195
pod := &kcorev1.Pod{
@@ -248,7 +245,7 @@ var _ = Describe("Informer Cache", func() {
248245
close(done)
249246
})
250247

251-
It("should be able to index an object field then retrieve objects by that field", func(done Done) {
248+
It("should be able to index an object field then retrieve objects by that field", func() {
252249
By("creating the cache")
253250
informer, err := cache.New(cfg, cache.Options{})
254251
Expect(err).NotTo(HaveOccurred())
@@ -277,7 +274,6 @@ var _ = Describe("Informer Cache", func() {
277274
Expect(len(listObj.Items)).To(Equal(1))
278275
actual := listObj.Items[0]
279276
Expect(actual.Name).To(Equal("test-pod-3"))
280-
close(done)
281277
})
282278
})
283279
})

0 commit comments

Comments
 (0)