Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TalShorSap committed Aug 17, 2023
1 parent c142578 commit 68a6a61
Showing 1 changed file with 54 additions and 15 deletions.
69 changes: 54 additions & 15 deletions controllers/serviceinstance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,27 +910,60 @@ var _ = Describe("ServiceInstance controller", func() {
})

Context("Orphan mitigation", func() {
recoveredInstance := smclientTypes.ServiceInstance{
ID: fakeInstanceID,
Name: fakeInstanceName,
LastOperation: &smClientTypes.Operation{State: smClientTypes.SUCCEEDED, Type: smClientTypes.CREATE},
}

BeforeEach(func() {
smInstance := &smclientTypes.ServiceInstance{ID: fakeInstanceID, LastOperation: &smClientTypes.Operation{State: smClientTypes.FAILED, Type: smClientTypes.DELETE, DeletionScheduled: time.Now()}}
fakeClient.GetInstanceByIDReturns(smInstance, nil)
fakeClient.ProvisionReturns(nil, fmt.Errorf("ERROR"))
recoveredInstance.LastOperation = &smClientTypes.Operation{State: smClientTypes.FAILED, Type: smClientTypes.DELETE, DeletionScheduled: time.Now()}
fakeClient.ListInstancesReturns(&smclientTypes.ServiceInstances{
ServiceInstances: []smclientTypes.ServiceInstance{recoveredInstance}}, nil)
fakeClient.DeprovisionReturns("", fmt.Errorf("sm failed to delete instance"))
})

AfterEach(func() {
fakeClient.DeprovisionReturns("", nil)
deleteInstance(ctx, serviceInstance, true)
})

Context("delete failed", func() {
It("polls until sm return not found", func() {
serviceInstance = createInstance(ctx, instanceSpec, true)

fakeClient.DeprovisionReturns("", fmt.Errorf("sm failed to delete instance"))
fakeClient.GetInstanceByIDReturns(&smclientTypes.ServiceInstance{ID: fakeInstanceID, Ready: true,
LastOperation: &smClientTypes.Operation{State: smClientTypes.INPROGRESS, Type: smClientTypes.DELETE,
DeletionScheduled: time.Now()}}, nil)

k8sClient.Delete(ctx, serviceInstance)
verifyOrphanMitigationStatus(true, defaultLookupKey, ctx)
fakeClient.GetInstanceByIDReturns(nil, &sm.ServiceManagerError{
StatusCode: http.StatusNotFound,
Description: "deleted successfully",
})

Eventually(func() bool {
err := k8sClient.Get(ctx, defaultLookupKey, serviceInstance)
return apierrors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())

Expect(fakeClient.DeprovisionCallCount()).To(BeZero())
})
})

Context("recovery", func() {
FIt("polls until sm returns not found - and marks the resource for deletion", func() {
smInstance := smclientTypes.ServiceInstance{ID: fakeInstanceID, LastOperation: &smClientTypes.Operation{State: smClientTypes.FAILED, Type: smClientTypes.DELETE, DeletionScheduled: time.Now()}}
fakeClient.ListInstancesReturns(&smclientTypes.ServiceInstances{
ServiceInstances: []smclientTypes.ServiceInstance{smInstance}}, nil)
fakeClient.DeprovisionReturns("", fmt.Errorf("sm failed to delete instance"))
fakeClient.GetInstanceByIDReturns(&smInstance, nil)
serviceInstance = createInstance(ctx, instanceSpec, false)
verifyOrphanMitigationStatus(true, defaultLookupKey, ctx)

fakeClient.GetInstanceByIDReturns(nil, &sm.ServiceManagerError{
StatusCode: http.StatusNotFound,
Description: "deleted successfully",
})

Eventually(func() bool {
err := k8sClient.Get(ctx, defaultLookupKey, serviceInstance)
return apierrors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())

})
})

When("orphan mitigation in sm ends in delete failed", func() {
It("should mark the instance as in orphan mitigation and eventually remove the mark", func() {
serviceInstance = createInstance(ctx, instanceSpec, false)
Expand Down Expand Up @@ -965,6 +998,12 @@ var _ = Describe("ServiceInstance controller", func() {
}
return false
}, timeout, interval).Should(BeTrue())

Eventually(func() bool {
e := k8sClient.Get(ctx, defaultLookupKey, serviceInstance)
fmt.Println(e)
return false
}, timeout, interval).Should(BeTrue())
})
})
})
Expand Down

0 comments on commit 68a6a61

Please sign in to comment.