@@ -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 )
@@ -2279,6 +2279,32 @@ var _ = Describe("Patch", func() {
2279
2279
})
2280
2280
})
2281
2281
2282
+ var _ = Describe ("IgnoreNotFound" , func () {
2283
+ It ("should return nil on a 'NotFound' error" , func () {
2284
+ By ("creating a NotFound error" )
2285
+ err := apierrors .NewNotFound (schema.GroupResource {}, "" )
2286
+
2287
+ By ("returning no error" )
2288
+ Expect (client .IgnoreNotFound (err )).To (Succeed ())
2289
+ })
2290
+
2291
+ It ("should return the error on a status other than not found" , func () {
2292
+ By ("creating a BadRequest error" )
2293
+ err := apierrors .NewBadRequest ("" )
2294
+
2295
+ By ("returning an error" )
2296
+ Expect (client .IgnoreNotFound (err )).To (HaveOccurred ())
2297
+ })
2298
+
2299
+ It ("should return the error on a non-status error" , func () {
2300
+ By ("creating an fmt error" )
2301
+ err := fmt .Errorf ("arbitrary error" )
2302
+
2303
+ By ("returning an error" )
2304
+ Expect (client .IgnoreNotFound (err )).To (HaveOccurred ())
2305
+ })
2306
+ })
2307
+
2282
2308
type fakeReader struct {
2283
2309
Called int
2284
2310
}
0 commit comments