@@ -22,6 +22,7 @@ import (
22
22
. "github.com/onsi/ginkgo"
23
23
. "github.com/onsi/gomega"
24
24
kcorev1 "k8s.io/api/core/v1"
25
+ "k8s.io/apimachinery/pkg/api/errors"
25
26
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
27
"k8s.io/apimachinery/pkg/runtime"
27
28
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -102,8 +103,8 @@ var _ = Describe("Informer Cache", func() {
102
103
close (stop )
103
104
})
104
105
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 () {
107
108
By ("listing all services in the cluster" )
108
109
listObj := & kcorev1.ServiceList {}
109
110
Expect (informerCache .List (context .Background (), nil , listObj )).NotTo (HaveOccurred ())
@@ -119,10 +120,9 @@ var _ = Describe("Informer Cache", func() {
119
120
}
120
121
}
121
122
Expect (hasKubeService ).To (BeTrue ())
122
- close (done )
123
123
})
124
124
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 () {
126
126
By ("getting the Kubernetes service" )
127
127
svc := & kcorev1.Service {}
128
128
svcKey := client.ObjectKey {Namespace : "default" , Name : "kubernetes" }
@@ -131,10 +131,9 @@ var _ = Describe("Informer Cache", func() {
131
131
By ("verifying that the returned service looks reasonable" )
132
132
Expect (svc .Name ).To (Equal ("kubernetes" ))
133
133
Expect (svc .Namespace ).To (Equal ("default" ))
134
- close (done )
135
134
})
136
135
137
- It ("should support filtering by labels" , func (done Done ) {
136
+ It ("should support filtering by labels" , func () {
138
137
By ("listing pods with a particular label" )
139
138
// NB: each pod has a "test-label" equal to the pod name
140
139
out := kcorev1.PodList {}
@@ -146,10 +145,9 @@ var _ = Describe("Informer Cache", func() {
146
145
Expect (len (out .Items )).To (Equal (1 ))
147
146
actual := out .Items [0 ]
148
147
Expect (actual .Labels ["test-label" ]).To (Equal ("test-pod-2" ))
149
- close (done )
150
148
})
151
149
152
- It ("should be able to list objects by namespace" , func (done Done ) {
150
+ It ("should be able to list objects by namespace" , func () {
153
151
By ("listing pods in test-namespace-1" )
154
152
listObj := & kcorev1.PodList {}
155
153
Expect (informerCache .List (context .Background (),
@@ -161,10 +159,9 @@ var _ = Describe("Informer Cache", func() {
161
159
Expect (len (listObj .Items )).To (Equal (1 ))
162
160
actual := listObj .Items [0 ]
163
161
Expect (actual .Namespace ).To (Equal (testNamespaceOne ))
164
- close (done )
165
162
})
166
163
167
- It ("should deep copy the object unless told otherwise" , func (done Done ) {
164
+ It ("should deep copy the object unless told otherwise" , func () {
168
165
By ("retrieving a specific pod from the cache" )
169
166
out := & kcorev1.Pod {}
170
167
podKey := client.ObjectKey {Name : "test-pod-2" , Namespace : testNamespaceTwo }
@@ -178,21 +175,21 @@ var _ = Describe("Informer Cache", func() {
178
175
179
176
By ("verifying the pods are no longer equal" )
180
177
Expect (out ).NotTo (Equal (knownPod2 ))
181
- close (done )
182
178
})
183
179
184
- It ("should error out for missing objects" , func (done Done ) {
180
+ It ("should error out for missing objects" , func () {
185
181
By ("getting a service that does not exists" )
186
182
svc := & kcorev1.Service {}
187
183
svcKey := client.ObjectKey {Namespace : "unknown" , Name : "unknown" }
188
184
189
185
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 ))
192
189
})
193
190
})
194
191
195
- Describe ("Cache as an Informer" , func () {
192
+ Describe ("as an Informer" , func () {
196
193
It ("should be able to get informer for the object" , func (done Done ) {
197
194
By ("getting an shared index informer for a pod" )
198
195
pod := & kcorev1.Pod {
@@ -248,7 +245,7 @@ var _ = Describe("Informer Cache", func() {
248
245
close (done )
249
246
})
250
247
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 () {
252
249
By ("creating the cache" )
253
250
informer , err := cache .New (cfg , cache.Options {})
254
251
Expect (err ).NotTo (HaveOccurred ())
@@ -277,7 +274,6 @@ var _ = Describe("Informer Cache", func() {
277
274
Expect (len (listObj .Items )).To (Equal (1 ))
278
275
actual := listObj .Items [0 ]
279
276
Expect (actual .Name ).To (Equal ("test-pod-3" ))
280
- close (done )
281
277
})
282
278
})
283
279
})
0 commit comments