@@ -36,6 +36,8 @@ import (
3636 appsv1 "k8s.io/api/apps/v1"
3737 coordinationv1 "k8s.io/api/coordination/v1"
3838 corev1 "k8s.io/api/core/v1"
39+ policyv1 "k8s.io/api/policy/v1"
40+ policyv1beta1 "k8s.io/api/policy/v1beta1"
3941 apierrors "k8s.io/apimachinery/pkg/api/errors"
4042 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4143 "k8s.io/apimachinery/pkg/runtime"
@@ -1436,6 +1438,54 @@ var _ = Describe("Fake client", func() {
14361438 err := cl .Status ().Update (context .Background (), obj )
14371439 Expect (apierrors .IsNotFound (err )).To (BeTrue ())
14381440 })
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+ })
14391489})
14401490
14411491var _ = Describe ("Fake client builder" , func () {
0 commit comments