Skip to content

Commit

Permalink
add create test
Browse files Browse the repository at this point in the history
  • Loading branch information
TalShorSap committed Aug 20, 2023
1 parent 932da1b commit 2ba36fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions controllers/serviceinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ func (r *ServiceInstanceReconciler) createInstance(ctx context.Context, smClient
if provisionErr != nil {
log.Error(provisionErr, "failed to create service instance", "serviceOfferingName", serviceInstance.Spec.ServiceOfferingName,
"servicePlanName", serviceInstance.Spec.ServicePlanName)
if isOrphanMitigationError(provisionErr) {
log.Info(OrphanMitigationLog)
r.updateInstanceAsInOrphanMitigation(ctx, serviceInstance)
return ctrl.Result{}, r.updateStatus(ctx, serviceInstance)
}
return r.handleError(ctx, smClientTypes.CREATE, provisionErr, serviceInstance)
}

Expand Down
24 changes: 24 additions & 0 deletions controllers/serviceinstance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,30 @@ var _ = Describe("ServiceInstance controller", func() {
}}
})

Context("create failed", func() {
It("polls until sm returns not found", func() {
fakeClient.ProvisionReturns(nil, orphanMitigationErr)
fakeClient.DeprovisionReturns("", orphanMitigationErr)
smInstance := smclientTypes.ServiceInstance{ID: fakeInstanceID, LastOperation: &smClientTypes.Operation{State: smClientTypes.FAILED, Type: smClientTypes.DELETE, DeletionScheduled: time.Now()}}
fakeClient.GetInstanceByIDReturns(&smInstance, nil)
fakeClient.ListInstancesReturns(&smclientTypes.ServiceInstances{
ServiceInstances: []smclientTypes.ServiceInstance{smInstance}}, nil)
serviceInstance = createInstance(ctx, instanceSpec, false)
verifyOrphanMitigationStatus(true, defaultLookupKey, ctx)

/* only after sm returns not found the instance should be deleted */
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())
})
})

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

0 comments on commit 2ba36fd

Please sign in to comment.