Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Adjust test after fixing repetitive update issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Sep 27, 2019
1 parent 4854c3b commit 33a1ce7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
3 changes: 1 addition & 2 deletions pkg/apis/servicecatalog/v1beta1/recalculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func (in *ServiceBinding) RecalculatePrinterColumnStatusFields() {

// IsUserSpecifiedClassOrPlan returns true if user specified class or plan is not empty
func (in *ServiceInstance) IsUserSpecifiedClassOrPlan() bool {
return in.Status.UserSpecifiedPlanName != "" ||
in.Status.UserSpecifiedClassName != ""
return in.Status.UserSpecifiedPlanName != "" && in.Status.UserSpecifiedClassName != ""
}

func getServiceInstanceLastConditionState(status *ServiceInstanceStatus) string {
Expand Down
13 changes: 0 additions & 13 deletions pkg/controller/controller_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2954,19 +2954,6 @@ func setServiceInstanceLastOperation(instance *v1beta1.ServiceInstance, operatio
}
}

func (c *controller) resolveServiceInstanceUserSpecifiedClassAndPlan(instance *v1beta1.ServiceInstance) bool {
if instance.Status.UserSpecifiedPlanName != "" ||
instance.Status.UserSpecifiedClassName != "" {
return false
}

class, plan := getServiceInstanceCommonClassAndPlan(*instance)
instance.Status.UserSpecifiedClassName = class
instance.Status.UserSpecifiedPlanName = plan

return true
}

func getServiceInstanceCommonClassAndPlan(instance v1beta1.ServiceInstance) (string, string) {
var class, plan string
if instance.Spec.ClusterServiceClassSpecified() && instance.Spec.ClusterServicePlanSpecified() {
Expand Down
36 changes: 19 additions & 17 deletions pkg/controller/controller_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ func TestReconcileServiceInstanceNotInitializedStatus(t *testing.T) {
}

expectedStatus := v1beta1.ServiceInstanceStatus{
Conditions: []v1beta1.ServiceInstanceCondition{},
DeprovisionStatus: v1beta1.ServiceInstanceDeprovisionStatusNotRequired,
UserSpecifiedPlanName: "test",
UserSpecifiedClassName: "ClusterServiceClass/test",
Conditions: []v1beta1.ServiceInstanceCondition{},
DeprovisionStatus: v1beta1.ServiceInstanceDeprovisionStatusNotRequired,
}

err := reconcileServiceInstance(t, testController, instance)
Expand Down Expand Up @@ -3625,7 +3627,7 @@ func TestReconcileServiceInstanceWithStatusUpdateError(t *testing.T) {

instance := getTestServiceInstanceWithClusterRefs()
instance.Status.UserSpecifiedClassName = fmt.Sprintf("ClusterServiceClass/%s", instance.Spec.GetSpecifiedClusterServiceClass())
instance.Status.UserSpecifiedClassName = instance.Spec.GetSpecifiedClusterServicePlan()
instance.Status.UserSpecifiedPlanName = instance.Spec.GetSpecifiedClusterServicePlan()

fakeCatalogClient.AddReactor("update", "serviceinstances", func(action clientgotesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("update error")
Expand Down Expand Up @@ -4820,9 +4822,9 @@ func TestReconcileServiceInstanceUpdateParameters(t *testing.T) {
})

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)
assertServiceInstanceOperationSuccessWithParameters(t, updatedServiceInstance, v1beta1.ServiceInstanceOperationUpdate, testClusterServicePlanName, testClusterServicePlanGUID, expectedParameters, expectedParametersChecksum, instance)

updateObject, ok := updatedServiceInstance.(*v1beta1.ServiceInstance)
Expand Down Expand Up @@ -4922,9 +4924,9 @@ func TestReconcileServiceInstanceDeleteParameters(t *testing.T) {
})

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)
assertServiceInstanceOperationSuccess(t, updatedServiceInstance, v1beta1.ServiceInstanceOperationUpdate, testClusterServicePlanName, testClusterServicePlanGUID, instance)

updateObject, ok := updatedServiceInstance.(*v1beta1.ServiceInstance)
Expand Down Expand Up @@ -5152,9 +5154,9 @@ func TestReconcileServiceInstanceUpdateDashboardURLResponse(t *testing.T) {
})

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)

if tc.enableUpdateDashboardURL {
if tc.newDashboardURL != "" {
Expand Down Expand Up @@ -5264,9 +5266,9 @@ func TestReconcileServiceInstanceUpdatePlan(t *testing.T) {
})

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)
assertServiceInstanceOperationSuccessWithParameters(t, updatedServiceInstance, v1beta1.ServiceInstanceOperationUpdate, testClusterServicePlanName, testClusterServicePlanGUID, oldParameters, oldParametersChecksum, instance)

updateObject, ok := updatedServiceInstance.(*v1beta1.ServiceInstance)
Expand Down Expand Up @@ -5345,9 +5347,9 @@ func TestReconcileServiceInstanceWithUpdateCallFailure(t *testing.T) {
}

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)
assertServiceInstanceRequestRetriableError(t, updatedServiceInstance, v1beta1.ServiceInstanceOperationUpdate, errorErrorCallingUpdateInstanceReason, testClusterServicePlanName, testClusterServicePlanGUID, instance)

events := getRecordedEvents(testController)
Expand Down Expand Up @@ -5445,9 +5447,9 @@ func TestReconcileServiceInstanceWithUpdateFailure(t *testing.T) {
}

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)
assertServiceInstanceUpdateRequestFailingErrorNoOrphanMitigation(t, updatedServiceInstance, v1beta1.ServiceInstanceOperationUpdate, errorUpdateInstanceCallFailedReason, tc.expectedFailureReason, instance)

events := getRecordedEvents(testController)
Expand Down Expand Up @@ -5726,9 +5728,9 @@ func TestReconcileServiceInstanceUpdateAsynchronous(t *testing.T) {
})

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 2)
assertNumberOfActions(t, actions, 1)

updatedServiceInstance := assertUpdateStatus(t, actions[1], instance)
updatedServiceInstance := assertUpdateStatus(t, actions[0], instance)
assertServiceInstanceAsyncStartInProgress(t, updatedServiceInstance, v1beta1.ServiceInstanceOperationUpdate, testOperation, testClusterServicePlanName, testClusterServicePlanGUID, instance)

// verify no kube resources created.
Expand Down

0 comments on commit 33a1ce7

Please sign in to comment.