@@ -28,7 +28,7 @@ import (
28
28
. "github.com/onsi/gomega"
29
29
appsv1 "k8s.io/api/apps/v1"
30
30
corev1 "k8s.io/api/core/v1"
31
- "k8s.io/apimachinery/pkg/api/errors"
31
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
32
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
33
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
34
34
"k8s.io/apimachinery/pkg/runtime"
@@ -232,7 +232,7 @@ var _ = Describe("Client", func() {
232
232
By ("creating the object a second time" )
233
233
err = cl .Create (context .TODO (), old )
234
234
Expect (err ).To (HaveOccurred ())
235
- Expect (errors .IsAlreadyExists (err )).To (BeTrue ())
235
+ Expect (apierrors .IsAlreadyExists (err )).To (BeTrue ())
236
236
237
237
close (done )
238
238
})
@@ -281,7 +281,7 @@ var _ = Describe("Client", func() {
281
281
282
282
actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
283
283
Expect (err ).To (HaveOccurred ())
284
- Expect (errors .IsNotFound (err )).To (BeTrue ())
284
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
285
285
Expect (actual ).To (Equal (& appsv1.Deployment {}))
286
286
287
287
close (done )
@@ -371,7 +371,7 @@ var _ = Describe("Client", func() {
371
371
By ("creating the object a second time" )
372
372
err = cl .Create (context .TODO (), u )
373
373
Expect (err ).To (HaveOccurred ())
374
- Expect (errors .IsAlreadyExists (err )).To (BeTrue ())
374
+ Expect (apierrors .IsAlreadyExists (err )).To (BeTrue ())
375
375
376
376
close (done )
377
377
})
@@ -420,7 +420,7 @@ var _ = Describe("Client", func() {
420
420
421
421
actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
422
422
Expect (err ).To (HaveOccurred ())
423
- Expect (errors .IsNotFound (err )).To (BeTrue ())
423
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
424
424
Expect (actual ).To (Equal (& appsv1.Deployment {}))
425
425
426
426
close (done )
@@ -2255,6 +2255,32 @@ var _ = Describe("Patch", func() {
2255
2255
})
2256
2256
})
2257
2257
2258
+ var _ = Describe ("IgnoreNotFound" , func () {
2259
+ It ("should return nil on a 'NotFound' error" , func () {
2260
+ By ("creating a NotFound error" )
2261
+ err := apierrors .NewNotFound (schema.GroupResource {}, "" )
2262
+
2263
+ By ("returning no error" )
2264
+ Expect (client .IgnoreNotFound (err )).To (Succeed ())
2265
+ })
2266
+
2267
+ It ("should return the error on a status other than not found" , func () {
2268
+ By ("creating a BadRequest error" )
2269
+ err := apierrors .NewBadRequest ("" )
2270
+
2271
+ By ("returning an error" )
2272
+ Expect (client .IgnoreNotFound (err )).To (HaveOccurred ())
2273
+ })
2274
+
2275
+ It ("should return the error on a non-status error" , func () {
2276
+ By ("creating an fmt error" )
2277
+ err := fmt .Errorf ("arbitrary error" )
2278
+
2279
+ By ("returning an error" )
2280
+ Expect (client .IgnoreNotFound (err )).To (HaveOccurred ())
2281
+ })
2282
+ })
2283
+
2258
2284
type fakeReader struct {
2259
2285
Called int
2260
2286
}
0 commit comments