Skip to content

Commit

Permalink
allows update to return a dashboard_url (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
x6j8x authored and jacknewberry committed Oct 25, 2018
1 parent c37f78a commit c7734df
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 3 deletions.
5 changes: 4 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ func (h serviceBrokerHandler) update(w http.ResponseWriter, req *http.Request) {
if updateServiceSpec.IsAsync {
statusCode = http.StatusAccepted
}
h.respond(w, statusCode, UpdateResponse{OperationData: updateServiceSpec.OperationData})
h.respond(w, statusCode, UpdateResponse{
OperationData: updateServiceSpec.OperationData,
DashboardURL: updateServiceSpec.DashboardURL,
})
}

func (h serviceBrokerHandler) deprovision(w http.ResponseWriter, req *http.Request) {
Expand Down
14 changes: 13 additions & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ var _ = Describe("Service Broker API", func() {
fakeServiceBroker.DashboardURL = "some-dashboard-url"
})

It("returns json with dasboard URL", func() {
It("returns json with dashboard URL", func() {
response := makeInstanceProvisioningRequest(instanceID, provisionDetails, "")
Expect(response.Body).To(MatchJSON(fixture("provisioning_with_dashboard.json")))
})
Expand Down Expand Up @@ -915,6 +915,18 @@ var _ = Describe("Service Broker API", func() {
})
})
})

Context("when the broker returns a dashboard URL", func() {
BeforeEach(func() {
fakeServiceBroker.DashboardURL = "some-dashboard-url"
})

It("returns json with dashboard URL", func() {
response := makeInstanceUpdateRequest(instanceID, details, "", "2.14")
Expect(response.Body).To(MatchJSON(fixture("updating_with_dashboard.json")))
})
})

})

Context("when the broker indicates that it needs async support", func() {
Expand Down
2 changes: 1 addition & 1 deletion fakes/fake_service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (fakeBroker *FakeServiceBroker) Update(context context.Context, instanceID
fakeBroker.UpdateDetails = details
fakeBroker.UpdatedInstanceIDs = append(fakeBroker.UpdatedInstanceIDs, instanceID)
fakeBroker.AsyncAllowed = asyncAllowed
return brokerapi.UpdateServiceSpec{IsAsync: fakeBroker.ShouldReturnAsync, OperationData: fakeBroker.OperationDataToReturn}, nil
return brokerapi.UpdateServiceSpec{IsAsync: fakeBroker.ShouldReturnAsync, OperationData: fakeBroker.OperationDataToReturn, DashboardURL: fakeBroker.DashboardURL}, nil
}

func (fakeBroker *FakeServiceBroker) Deprovision(context context.Context, instanceID string, details brokerapi.DeprovisionDetails, asyncAllowed bool) (brokerapi.DeprovisionServiceSpec, error) {
Expand Down
3 changes: 3 additions & 0 deletions fixtures/updating_with_dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dashboard_url": "some-dashboard-url"
}
1 change: 1 addition & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ProvisioningResponse struct {
}

type UpdateResponse struct {
DashboardURL string `json:"dashboard_url,omitempty"`
OperationData string `json:"operation,omitempty"`
}

Expand Down
24 changes: 24 additions & 0 deletions response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ var _ = Describe("Provisioning Response", func() {
})
})

var _ = Describe("Update Response", func() {
Describe("JSON encoding", func() {
Context("when the dashboard URL is not present", func() {
It("does not return it in the JSON", func() {
updateResponse := brokerapi.UpdateResponse{}
jsonString := `{}`

Expect(json.Marshal(updateResponse)).To(MatchJSON(jsonString))
})
})

Context("when the dashboard URL is present", func() {
It("returns it in the JSON", func() {
updateResponse := brokerapi.UpdateResponse{
DashboardURL: "http://example.com/broker_updated",
}
jsonString := `{"dashboard_url":"http://example.com/broker_updated"}`

Expect(json.Marshal(updateResponse)).To(MatchJSON(jsonString))
})
})
})
})

var _ = Describe("Binding Response", func() {
Describe("JSON encoding", func() {
It("has a credentials object", func() {
Expand Down
1 change: 1 addition & 0 deletions service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type UnbindDetails struct {

type UpdateServiceSpec struct {
IsAsync bool
DashboardURL string
OperationData string
}

Expand Down

0 comments on commit c7734df

Please sign in to comment.