Skip to content

Commit

Permalink
Fix in handlers as per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ddraganovv committed Dec 13, 2024
1 parent 8dc4adc commit de22dd0
Showing 1 changed file with 1 addition and 83 deletions.
84 changes: 1 addition & 83 deletions api/handlers/service_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,6 @@ var _ = Describe("ServiceBinding", func() {
requestValidator.DecodeAndValidateJSONPayloadStub = decodeAndValidatePayloadStub(&payload)
})

When("binding to a managed service instance", func() {
BeforeEach(func() {
serviceInstanceRepo.GetServiceInstanceReturns(repositories.ServiceInstanceRecord{
GUID: "service-instance-guid",
SpaceGUID: "space-guid",
Type: korifiv1alpha1.ManagedType,
}, nil)

serviceBindingRepo.CreateServiceBindingReturns(repositories.ServiceBindingRecord{
GUID: "service-binding-guid",
Type: korifiv1alpha1.CFServiceBindingTypeKey,
}, nil)
})

It("creates a binding", func() {
Expect(serviceInstanceRepo.GetServiceInstanceCallCount()).To(Equal(1))
Expect(serviceBindingRepo.CreateServiceBindingCallCount()).To(Equal(1))
_, actualAuthInfo, createServiceBindingMessage := serviceBindingRepo.CreateServiceBindingArgsForCall(0)
Expect(actualAuthInfo).To(Equal(authInfo))
Expect(createServiceBindingMessage.ServiceInstanceGUID).To(Equal("service-instance-guid"))
Expect(createServiceBindingMessage.SpaceGUID).To(Equal("space-guid"))
Expect(createServiceBindingMessage.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeKey))
Expect(rr).To(HaveHTTPStatus(http.StatusAccepted))
Expect(rr).To(HaveHTTPHeaderWithValue("Location",
ContainSubstring("/v3/jobs/managed_service_binding.create~service-binding-guid")))
})

When("creating the ServiceBinding errors", func() {
BeforeEach(func() {
serviceBindingRepo.CreateServiceBindingReturns(repositories.ServiceBindingRecord{}, errors.New("boom"))
})

It("returns an error", func() {
expectUnknownError()
})
})
})

When("binding to a user provided service instance", func() {
BeforeEach(func() {
serviceInstanceRepo.GetServiceInstanceReturns(repositories.ServiceInstanceRecord{
Expand All @@ -138,55 +100,11 @@ var _ = Describe("ServiceBinding", func() {
}, nil)
})

It("returns an error", func() {
It("returns an unprocessable entity error", func() {
Expect(serviceBindingRepo.CreateServiceBindingCallCount()).To(Equal(0))
expectUnprocessableEntityError("Service credential bindings of type 'key' are not supported for user-provided service instances.")
})
})

It("validates the payload", func() {
Expect(requestValidator.DecodeAndValidateJSONPayloadCallCount()).To(Equal(1))
actualReq, _ := requestValidator.DecodeAndValidateJSONPayloadArgsForCall(0)
Expect(bodyString(actualReq)).To(Equal("the-json-body"))
})

When("the request body is invalid json", func() {
BeforeEach(func() {
requestValidator.DecodeAndValidateJSONPayloadReturns(errors.New("boom"))
})

It("returns an error", func() {
expectUnknownError()
})
})

It("gets the service instance", func() {
Expect(serviceInstanceRepo.GetServiceInstanceCallCount()).To(Equal(1))
_, actualAuthInfo, actualServiceInstanceGUID := serviceInstanceRepo.GetServiceInstanceArgsForCall(0)
Expect(actualAuthInfo).To(Equal(authInfo))
Expect(actualServiceInstanceGUID).To(Equal("service-instance-guid"))
})

When("getting the service instance is forbidden", func() {
BeforeEach(func() {
serviceInstanceRepo.GetServiceInstanceReturns(repositories.ServiceInstanceRecord{}, apierrors.NewForbiddenError(nil, repositories.ServiceInstanceResourceType))
})

It("returns a not found error", func() {
expectNotFoundError(repositories.ServiceInstanceResourceType)
})
})

When("getting the ServiceInstance errors", func() {
BeforeEach(func() {
serviceInstanceRepo.GetServiceInstanceReturns(repositories.ServiceInstanceRecord{}, errors.New("boom"))
})

It("returns an error and doesn't create the ServiceBinding", func() {
expectUnknownError()
Expect(serviceBindingRepo.CreateServiceBindingCallCount()).To(Equal(0))
})
})
})

When("creating a service binding of type app", func() {
Expand Down

0 comments on commit de22dd0

Please sign in to comment.