Skip to content

Commit

Permalink
added test cases for get binding operations
Browse files Browse the repository at this point in the history
[#165673700]

Signed-off-by: Derik Evangelista <[email protected]>
Co-authored-by: Derik Evangelista <[email protected]>
  • Loading branch information
FelisiaM and Derik Evangelista committed May 16, 2019
1 parent 0689a56 commit 9e62cc5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,7 @@ var _ = Describe("Service Broker API", func() {
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
response = makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
Expect(response.Body).To(MatchJSON(`{"description":"get binding endpoint only supported starting with OSB version 2.14"}`))
})

It("fails for GetBinding request", func() {
Expand Down Expand Up @@ -1871,6 +1872,23 @@ var _ = Describe("Service Broker API", func() {
Expect(response.StatusCode).To(Equal(http.StatusOK))
Expect(response.Body).To(MatchJSON(fixture("binding.json")))
})

It("returns 500 when lastBindingOperation returns an unknown error", func() {
fakeAsyncServiceBroker.LastBindingOperationError = errors.New("unknown error")

response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
Expect(response.StatusCode).To(Equal(http.StatusInternalServerError))
})

It("returns the appropriate when lastBindingOperation returns a known error", func() {
fakeAsyncServiceBroker.LastBindingOperationError = brokerapi.NewFailureResponse(
errors.New("I failed in unique and interesting ways"),
http.StatusTeapot,
"interesting-failure",
)
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
Expect(response.StatusCode).To(Equal(http.StatusTeapot))
})
})
})
})
Expand Down
5 changes: 3 additions & 2 deletions fakes/fake_service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type FakeServiceBroker struct {
UnbindError error
DeprovisionError error
LastOperationError error
LastBindingOperationError error
UpdateError error
GetInstanceError error
GetBindingError error
Expand Down Expand Up @@ -412,8 +413,8 @@ func (fakeBroker *FakeServiceBroker) LastBindingOperation(context context.Contex
fakeBroker.ReceivedContext = val
}

if fakeBroker.LastOperationError != nil {
return brokerapi.LastOperation{}, fakeBroker.LastOperationError
if fakeBroker.LastBindingOperationError != nil {
return brokerapi.LastOperation{}, fakeBroker.LastBindingOperationError
}

return brokerapi.LastOperation{State: fakeBroker.LastOperationState, Description: fakeBroker.LastOperationDescription}, nil
Expand Down

0 comments on commit 9e62cc5

Please sign in to comment.