Skip to content

Commit

Permalink
Add more provisioning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobebway committed Nov 22, 2019
1 parent 97542a1 commit 968ee15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 6 additions & 6 deletions components/application-broker/internal/broker/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ func (svc *ProvisionService) do(iID internal.InstanceID, opID internal.Operation
applicationID := string(appID)
applicationName := string(appName)

// enable the namespace default Knative Broker
if err := svc.enableDefaultKnativeBroker(namespace); err != nil {
// create Kyma EventActivation
if err := svc.createEaOnSuccessProvision(applicationName, applicationID, namespace, displayName, iID); err != nil {
instanceState = internal.InstanceStateFailed
opState = internal.OperationStateFailed
opDesc = fmt.Sprintf("provisioning failed while enabling default Knative Broker for namespace: %s on error: %s", namespace, err)
opDesc = fmt.Sprintf("provisioning failed while creating EventActivation on error: %s", err)
svc.updateStates(iID, opID, instanceState, opState, opDesc)
return
}
Expand All @@ -255,11 +255,11 @@ func (svc *ProvisionService) do(iID internal.InstanceID, opID internal.Operation
return
}

// create Kyma EventActivation
if err := svc.createEaOnSuccessProvision(applicationName, applicationID, namespace, displayName, iID); err != nil {
// enable the namespace default Knative Broker
if err := svc.enableDefaultKnativeBroker(namespace); err != nil {
instanceState = internal.InstanceStateFailed
opState = internal.OperationStateFailed
opDesc = fmt.Sprintf("provisioning failed while creating EventActivation on error: %s", err)
opDesc = fmt.Sprintf("provisioning failed while enabling default Knative Broker for namespace: %s on error: %s", namespace, err)
svc.updateStates(iID, opID, instanceState, opState, opDesc)
return
}
Expand Down
13 changes: 12 additions & 1 deletion components/application-broker/internal/broker/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,17 @@ func TestDoProvision(t *testing.T) {
}

for _, tc := range []testCase{
{
name: "provision fail no channel found",
givenCanProvisionOutput: access.CanProvisionOutput{Allowed: true},
expectedOpState: internal.OperationStateFailed,
expectedOpDesc: `provisioning failed while persisting Knative Subscription for application: ec-prod namespace: example-namespace on error: getting the Knative channel for the application [ec-prod]: channels.messaging.knative.dev "" not found`,
expectedEventActivationCreated: true,
expectedInstanceState: internal.InstanceStateFailed,
initialObjs: []runtime.Object{
bt.NewAppNamespace(string(appNs), false),
},
},
{
name: "provision success subscription created before",
givenCanProvisionOutput: access.CanProvisionOutput{Allowed: true},
Expand Down Expand Up @@ -866,7 +877,7 @@ func TestDoProvision(t *testing.T) {
mockServiceInstanceGetter := &automock.ServiceInstanceGetter{}
defer mockServiceInstanceGetter.AssertExpectations(t)

mockOperationStorage.On("UpdateStateDesc", iID, opID, internal.OperationStateSucceeded, fixProvisionSucceeded()).Return(nil).Once()
mockOperationStorage.On("UpdateStateDesc", iID, opID, tc.expectedOpState, &tc.expectedOpDesc).Return(nil).Once()
mockAccessChecker.On("CanProvision", fixInstanceID(), fixAppServiceID(), fixNs(), time.Minute).Return(tc.givenCanProvisionOutput, tc.givenCanProvisionError)
mockInstanceStorage.On("UpdateState", fixInstanceID(), tc.expectedInstanceState).Return(nil).Once()
if tc.expectedEventActivationCreated {
Expand Down

0 comments on commit 968ee15

Please sign in to comment.