@@ -36,6 +36,8 @@ import (
36
36
appsv1 "k8s.io/api/apps/v1"
37
37
coordinationv1 "k8s.io/api/coordination/v1"
38
38
corev1 "k8s.io/api/core/v1"
39
+ policyv1 "k8s.io/api/policy/v1"
40
+ policyv1beta1 "k8s.io/api/policy/v1beta1"
39
41
apierrors "k8s.io/apimachinery/pkg/api/errors"
40
42
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
41
43
"k8s.io/apimachinery/pkg/runtime"
@@ -1436,6 +1438,54 @@ var _ = Describe("Fake client", func() {
1436
1438
err := cl .Status ().Update (context .Background (), obj )
1437
1439
Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1438
1440
})
1441
+
1442
+ evictionTypes := []client.Object {
1443
+ & policyv1beta1.Eviction {},
1444
+ & policyv1.Eviction {},
1445
+ }
1446
+ for _ , tp := range evictionTypes {
1447
+ It ("should delete a pod through the eviction subresource" , func () {
1448
+ pod := & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1449
+
1450
+ cl := NewClientBuilder ().WithObjects (pod ).Build ()
1451
+
1452
+ err := cl .SubResource ("eviction" ).Create (context .Background (), pod , tp )
1453
+ Expect (err ).NotTo (HaveOccurred ())
1454
+
1455
+ err = cl .Get (context .Background (), client .ObjectKeyFromObject (pod ), pod )
1456
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1457
+ })
1458
+
1459
+ It ("should return not found when attempting to evict a pod that doesn't exist" , func () {
1460
+ cl := NewClientBuilder ().Build ()
1461
+
1462
+ pod := & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1463
+ err := cl .SubResource ("eviction" ).Create (context .Background (), pod , tp )
1464
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1465
+ })
1466
+
1467
+ It ("should return not found when attempting to evict something other than a pod" , func () {
1468
+ ns := & corev1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "foo" }}
1469
+ cl := NewClientBuilder ().WithObjects (ns ).Build ()
1470
+
1471
+ err := cl .SubResource ("eviction" ).Create (context .Background (), ns , tp )
1472
+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1473
+ })
1474
+
1475
+ It ("should return an error when using the wrong subresource" , func () {
1476
+ cl := NewClientBuilder ().Build ()
1477
+
1478
+ err := cl .SubResource ("eviction-subresource" ).Create (context .Background (), & corev1.Namespace {}, tp )
1479
+ Expect (err ).NotTo (BeNil ())
1480
+ })
1481
+ }
1482
+
1483
+ It ("should error when creating an eviction with the wrong type" , func () {
1484
+
1485
+ cl := NewClientBuilder ().Build ()
1486
+ err := cl .SubResource ("eviction" ).Create (context .Background (), & corev1.Pod {}, & corev1.Namespace {})
1487
+ Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
1488
+ })
1439
1489
})
1440
1490
1441
1491
var _ = Describe ("Fake client builder" , func () {
0 commit comments