Skip to content

Commit

Permalink
added unit test for LastBindingOperation
Browse files Browse the repository at this point in the history
[#165673700]

Signed-off-by: Felisia Martini <[email protected]>
Co-authored-by: Felisia Martini <[email protected]>
  • Loading branch information
Derik Evangelista and FelisiaM committed May 16, 2019
1 parent 9e62cc5 commit 75d0d93
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 906 deletions.
37 changes: 5 additions & 32 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ var _ = Describe("Service Broker API", func() {
Describe("OriginatingIdentityHeader", func() {

var (
fakeServiceBroker *fakes.AutoFakeServiceBrokerNew
fakeServiceBroker *fakes.AutoFakeServiceBroker
req *http.Request
testServer *httptest.Server
)

BeforeEach(func() {
fakeServiceBroker = new(fakes.AutoFakeServiceBrokerNew)
fakeServiceBroker = new(fakes.AutoFakeServiceBroker)
brokerAPI = brokerapi.New(fakeServiceBroker, brokerLogger, credentials)

testServer = httptest.NewServer(brokerAPI)
Expand Down Expand Up @@ -1400,7 +1400,7 @@ var _ = Describe("Service Broker API", func() {

Describe("binding lifecycle endpoint", func() {

makeLastBindingOperationRequestWithSpecificAPIVersion := func(instanceID, bindingID string, apiVersion string) *testflight.Response {
makeLastBindingOperationRequest := func(instanceID, bindingID string) *testflight.Response {
response := &testflight.Response{}
testflight.WithServer(brokerAPI, func(r *testflight.Requester) {
path := fmt.Sprintf("/v2/service_instances/%s/service_bindings/%s/last_operation", instanceID, bindingID)
Expand All @@ -1411,9 +1411,7 @@ var _ = Describe("Service Broker API", func() {

Expect(err).NotTo(HaveOccurred())

if apiVersion != "" {
request.Header.Add("X-Broker-Api-Version", apiVersion)
}
request.Header.Add("X-Broker-Api-Version", "2.14")
request.Header.Add("Content-Type", "application/json")
request.SetBasicAuth("username", "password")

Expand Down Expand Up @@ -1836,14 +1834,6 @@ var _ = Describe("Service Broker API", func() {
Expect(response.Body).To(MatchJSON(fixture("binding.json")))
})

It("fails for LastBindingOperation request", func() {
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "1.13")
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() {
response := makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "1.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
Expand All @@ -1862,7 +1852,7 @@ var _ = Describe("Service Broker API", func() {
It("can be polled with lastBindingOperation", func() {
fakeAsyncServiceBroker.LastOperationState = "succeeded"
fakeAsyncServiceBroker.LastOperationDescription = "some description"
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
response := makeLastBindingOperationRequest(instanceID, bindingID)
Expect(response.StatusCode).To(Equal(http.StatusOK))
Expect(response.Body).To(MatchJSON(fixture("last_operation_succeeded.json")))
})
Expand All @@ -1872,23 +1862,6 @@ 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
6 changes: 3 additions & 3 deletions domain/service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
)

//go:generate counterfeiter -o ../fakes/auto_fake_service_broker_new.go -fake-name AutoFakeServiceBrokerNew . ServiceBroker
//go:generate counterfeiter -o ../fakes/auto_fake_service_broker.go -fake-name AutoFakeServiceBroker . ServiceBroker

//Each method of the ServiceBroker interface maps to an individual endpoint of the Open Service Broker API.
//The specification is available here: https://github.com/openservicebrokerapi/servicebroker/blob/v2.14/spec.md
Expand Down Expand Up @@ -54,8 +54,8 @@ type ServiceBroker interface {
}

type LastOperation struct {
State LastOperationState
Description string
State LastOperationState `json:"state"`
Description string `json:"description"`
}

type LastOperationState string
Expand Down
3 changes: 1 addition & 2 deletions fakes/auto_fake_service_broker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 75d0d93

Please sign in to comment.