@@ -83,6 +83,13 @@ func withDriftDetection(d bool) modifier {
8383 }
8484}
8585
86+ func withDeletionTimestamp () modifier {
87+ return func (r * v1alpha1.ServiceInstance ) {
88+ ts := metav1 .Now ()
89+ r .ObjectMeta .DeletionTimestamp = & ts
90+ }
91+ }
92+
8693func serviceInstance (typ string , m ... modifier ) * v1alpha1.ServiceInstance {
8794 r := & v1alpha1.ServiceInstance {
8895 ObjectMeta : metav1.ObjectMeta {
@@ -379,6 +386,46 @@ func TestObserve(t *testing.T) {
379386 return m
380387 },
381388 },
389+ "DeletionFastPath_Exists" : {
390+ args : args {
391+ mg : serviceInstance ("managed" ,
392+ withExternalName (guid ),
393+ withSpace (spaceGUID ),
394+ withServicePlan (v1alpha1.ServicePlanParameters {ID : & servicePlan }),
395+ withDeletionTimestamp (), // triggers meta.WasDeleted short-circuit
396+ ),
397+ },
398+ want : want {
399+ mg : serviceInstance ("managed" ,
400+ withExternalName (guid ),
401+ withSpace (spaceGUID ),
402+ withServicePlan (v1alpha1.ServicePlanParameters {ID : & servicePlan }),
403+ withDeletionTimestamp (),
404+ // Status updated by UpdateObservation before early return
405+ withStatus (v1alpha1.ServiceInstanceObservation {ID : & guid , ServicePlan : & servicePlan }),
406+ ),
407+ // Early return only sets ResourceExists: true
408+ obs : managed.ExternalObservation {ResourceExists : true },
409+ err : nil ,
410+ },
411+ service : func () * fake.MockServiceInstance {
412+ m := & fake.MockServiceInstance {}
413+ m .On ("Get" , guid ).Return (
414+ // LastOperationFailed + Create would have produced ResourceExists:false in the normal path,
415+ // proving we exited early.
416+ & fake .NewServiceInstance ("managed" ).
417+ SetName (name ).
418+ SetGUID (guid ).
419+ SetServicePlan (servicePlan ).
420+ SetLastOperation (v1alpha1 .LastOperationCreate , v1alpha1 .LastOperationFailed ).
421+ ServiceInstance ,
422+ nil ,
423+ )
424+ // Fallback shouldn't be called, keep safe default.
425+ m .On ("Single" ).Return (fake .ServiceInstanceNil , fake .ErrNoResultReturned )
426+ return m
427+ },
428+ },
382429 "DriftDetectionLoop" : {
383430 args : args {
384431 mg : serviceInstance ("managed" , withExternalName (guid ), withSpace (spaceGUID ), withServicePlan (v1alpha1.ServicePlanParameters {ID : & servicePlan }), withParameters ("{\" foo\" :\" bar\" , \" baz\" : 1}" ), withDriftDetection (true )),
0 commit comments