Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add controller Service Instance test #1

Conversation

jasiu001
Copy link

Related to #3113. Controller tests for ServiceInstance.

Copy link
Owner

@piotrmiskiewicz piotrmiskiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create methods like AssertXXX(t *testing.T, ....) instead of Ensure

defer ct.TearDown()

require.NoError(t, ct.CreateClusterServiceClass())
require.NoError(t, ct.WaitForClusterServiceClass())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to wait for the class? the same for plan

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test waits for class and plans. In my opinion they wanted to be sure provision failed due lack of ServiceBroker not class or plans. Should it be omitted? I am not sure

// in this test the `instance.Generation` is not update so in `pkg/controller/controller_instance.go`
// in method `reconcileServiceInstanceAdd` will not increase `ObservedGeneration` value
// because `instance.Status.ObservedGeneration != instance.Generation` condition is not met
require.NoError(t, ct.EnsureInstanceObservedGeneration(0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not make sense

Reason: "ProvisionedSuccessfully",
}
require.NoError(t, ct.WaitForInstanceCondition(condition))
require.NoError(t, ct.CheckFeatureGate(state.enableFeatureGate))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you set the feature gate?
the name CheckFeatureGate is saying - check the feature gate, but I'm looking deeper and there is a logic with dashboardURL - let's discuss structure the test

}

// EnsureBrokerActionExist makes sure specific fake osb client action exist
func (ct *controllerTest) EnsureBrokerActionExist(actionType fakeosb.ActionType) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are methods like: NumberOfOSBProvisionCalls which can be used


// EnsureLastUpdateBrokerActionHasCorrectPlan makes sure osb client action with type "UpdateInstance"
// contains specific plan ID in request body parameters
func (ct *controllerTest) EnsureLastUpdateBrokerActionHasCorrectPlan(planID string) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a method which returns last update planID or create a method something like AssertLastOSBUpdatePlanID

defer ct.TearDown()

ct.SetupEmptyPlanListForOSBClient()
require.NoError(t, ct.CreateServiceBrokerWithIncreaseRelistRequests())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ct.CreateSimpleClusterServiceBroker(),

why do you need increasing relist requests

require.NoError(t, ct.WaitForServiceInstanceProcessedGeneration(generation))

// THEN
require.NoError(t, ct.EnsureBrokerActionExist(fakeosb.UpdateInstance))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ct.NumberOfUpdateCalls (you need to create such method, see other NumberOf... methods)


// THEN
require.NoError(t, ct.EnsureBrokerActionExist(fakeosb.UpdateInstance))
require.NoError(t, ct.EnsureBrokerActionWithParametersExist(state.expectedParams))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ct.AssertLastUpdateAction, see AssertLastBindRequest

Reason: state.orphanMitigationReason,
}
require.NoError(t, ct.EnsureServiceInstanceHasCondition(condition))
require.NoError(t, ct.EnsureServiceInstanceOrphanMitigationStatus(true))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AssertServiceinstanceOrphanMitigationStatus

Status: v1beta1.ConditionFalse,
}
require.NoError(t, ct.EnsureServiceInstanceHasNoCondition(condition))
require.NoError(t, ct.EnsureBrokerActionExist(fakeosb.ProvisionInstance))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ct.NumberOfProvisionCalls


// AssertBrokerActionWithParametersExist makes sure osb client action with type "UpdateInstance"
// contains specific parameters in request body parameters
func (ct *controllerTest) AssertBrokerActionWithParametersExist(parameters map[string]interface{}) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it asserts update action - fix the name


// AssertLastOSBUpdatePlanID makes sure osb client action with type "UpdateInstance"
// contains specific plan ID in request body parameters
func (ct *controllerTest) AssertLastOSBUpdatePlanID() error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, refactor all Assert* methods to have one argument t *testing.T, see existing AssertOSBBasicAuth

require.NoError(t, ct.AssertServiceInstanceDashboardURL())
} else {
require.NoError(t, ct.AssertServiceInstanceEmptyDashboardURL())
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try such test:

t.Run(tn, func(t *testing.T) {
			// GIVEN
			ct := newControllerTest(t)
			defer ct.TearDown()

			//if state.enableFeatureGate {
			oldValue := utilfeature.DefaultFeatureGate.Enabled(scfeatures.UpdateDashboardURL)
			utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("%v=%v", scfeatures.UpdateDashboardURL, state.enableFeatureGate))
			defer utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("%v=%v", scfeatures.UpdateDashboardURL, oldValue))
			//}

			require.NoError(t, ct.CreateSimpleClusterServiceBroker())
			require.NoError(t, ct.WaitForReadyBroker())

			// WHEN
			require.NoError(t, ct.CreateServiceInstance())


			// THEN
			require.NoError(t, ct.WaitForReadyInstance())

			ct.SetUpdateServiceInstanceResponseWithDashboardURL()

			ct.UpdateServiceInstanceParameters()

			time.Sleep(time.Second)

			if state.enableFeatureGate {
				require.NoError(t, ct.AssertServiceInstanceDashboardURL())
			} else {
				require.NoError(t, ct.AssertServiceInstanceEmptyDashboardURL())
			}
		})

@jasiu001 jasiu001 closed this Jun 12, 2019
@jasiu001 jasiu001 deleted the controller-test branch June 12, 2019 08:34
@jasiu001
Copy link
Author

PR moved to main fork #2667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants