@@ -568,7 +568,33 @@ var _ = Describe("Fake client", func() {
568568 Expect (obj .ObjectMeta .ResourceVersion ).To (Equal (trackerAddResourceVersion ))
569569 })
570570
571- It ("should be able to Delete" , func () {
571+ It ("should reject Delete with a mismatched ResourceVersion" , func () {
572+ bogusRV := "bogus"
573+ By ("Deleting with a mismatched ResourceVersion Precondition" )
574+ err := cl .Delete (context .Background (), dep , client.Preconditions {ResourceVersion : & bogusRV })
575+ Expect (apierrors .IsConflict (err )).To (BeTrue ())
576+
577+ list := & appsv1.DeploymentList {}
578+ err = cl .List (context .Background (), list , client .InNamespace ("ns1" ))
579+ Expect (err ).To (BeNil ())
580+ Expect (list .Items ).To (HaveLen (2 ))
581+ Expect (list .Items ).To (ConsistOf (* dep , * dep2 ))
582+ })
583+
584+ It ("should successfully Delete with a matching ResourceVersion" , func () {
585+ goodRV := trackerAddResourceVersion
586+ By ("Deleting with a matching ResourceVersion Precondition" )
587+ err := cl .Delete (context .Background (), dep , client.Preconditions {ResourceVersion : & goodRV })
588+ Expect (err ).To (BeNil ())
589+
590+ list := & appsv1.DeploymentList {}
591+ err = cl .List (context .Background (), list , client .InNamespace ("ns1" ))
592+ Expect (err ).To (BeNil ())
593+ Expect (list .Items ).To (HaveLen (1 ))
594+ Expect (list .Items ).To (ConsistOf (* dep2 ))
595+ })
596+
597+ It ("should be able to Delete with no ResourceVersion Precondition" , func () {
572598 By ("Deleting a deployment" )
573599 err := cl .Delete (context .Background (), dep )
574600 Expect (err ).To (BeNil ())
@@ -581,6 +607,21 @@ var _ = Describe("Fake client", func() {
581607 Expect (list .Items ).To (ConsistOf (* dep2 ))
582608 })
583609
610+ It ("should be able to Delete with no opts even if object's ResourceVersion doesn't match server" , func () {
611+ By ("Deleting a deployment" )
612+ depCopy := dep .DeepCopy ()
613+ depCopy .ResourceVersion = "bogus"
614+ err := cl .Delete (context .Background (), depCopy )
615+ Expect (err ).To (BeNil ())
616+
617+ By ("Listing all deployments in the namespace" )
618+ list := & appsv1.DeploymentList {}
619+ err = cl .List (context .Background (), list , client .InNamespace ("ns1" ))
620+ Expect (err ).To (BeNil ())
621+ Expect (list .Items ).To (HaveLen (1 ))
622+ Expect (list .Items ).To (ConsistOf (* dep2 ))
623+ })
624+
584625 It ("should handle finalizers on Update" , func () {
585626 namespacedName := types.NamespacedName {
586627 Name : "test-cm" ,
0 commit comments