Skip to content

Commit d97ebdd

Browse files
committed
Add support for arbitrary bind params
1 parent 10997ba commit d97ebdd

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

api_test.go

+27-3
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,15 @@ var _ = Describe("Service Broker API", func() {
453453
}
454454

455455
Describe("binding", func() {
456-
var details *brokerapi.BindDetails
456+
var (
457+
instanceID string
458+
bindingID string
459+
details *brokerapi.BindDetails
460+
)
457461

458462
BeforeEach(func() {
463+
instanceID = uniqueInstanceID()
464+
bindingID = uniqueBindingID()
459465
details = &brokerapi.BindDetails{
460466
AppGUID: "app_guid",
461467
PlanID: "plan_id",
@@ -465,8 +471,6 @@ var _ = Describe("Service Broker API", func() {
465471

466472
Context("when the associated instance exists", func() {
467473
It("calls Bind on the service broker with the instance and binding ids", func() {
468-
instanceID := uniqueInstanceID()
469-
bindingID := uniqueBindingID()
470474
makeBindingRequest(instanceID, bindingID, details)
471475
Expect(fakeServiceBroker.BoundInstanceIDs).To(ContainElement(instanceID))
472476
Expect(fakeServiceBroker.BoundBindingIDs).To(ContainElement(bindingID))
@@ -489,6 +493,26 @@ var _ = Describe("Service Broker API", func() {
489493
Expect(response.StatusCode).To(Equal(422))
490494
})
491495
})
496+
497+
Context("when there are arbitrary params", func() {
498+
BeforeEach(func() {
499+
details.Parameters = map[string]interface{}{
500+
"string": "some-string",
501+
"number": 1,
502+
"object": struct{ Name string }{"some-name"},
503+
"array": []interface{}{"a", "b", "c"},
504+
}
505+
})
506+
507+
It("calls Bind on the service broker with all params", func() {
508+
makeBindingRequest(instanceID, bindingID, details)
509+
Expect(fakeServiceBroker.BoundBindingDetails.Parameters["string"]).To(Equal("some-string"))
510+
Expect(fakeServiceBroker.BoundBindingDetails.Parameters["number"]).To(Equal(1.0))
511+
Expect(fakeServiceBroker.BoundBindingDetails.Parameters["array"]).To(Equal([]interface{}{"a", "b", "c"}))
512+
actual, _ := fakeServiceBroker.BoundBindingDetails.Parameters["object"].(map[string]interface{})
513+
Expect(actual["Name"]).To(Equal("some-name"))
514+
})
515+
})
492516
})
493517

494518
Context("when the associated instance does not exist", func() {

matchers/marshal_to_json_matcher.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func (m *marshalToJSONMatcher) Match(actual interface{}) (success bool, err erro
3232
}
3333

3434
func (m *marshalToJSONMatcher) FailureMessage(actual interface{}) (message string) {
35-
return fmt.Sprintf("expected %s to equal %s", actual, m.expectedJSON)
35+
return fmt.Sprintf("expected %s to equal %s", actual, m.expectedJSON)
3636
}
3737

3838
func (m *marshalToJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) {
39-
return fmt.Sprintf("expected %s not to equal %s", actual, m.expectedJSON)
40-
}
39+
return fmt.Sprintf("expected %s not to equal %s", actual, m.expectedJSON)
40+
}

service_broker.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type ServiceDetails struct {
2121
}
2222

2323
type BindDetails struct {
24-
AppGUID string `json:"app_guid"`
25-
PlanID string `json:"plan_id"`
26-
ServiceID string `json:"service_id"`
24+
AppGUID string `json:"app_guid"`
25+
PlanID string `json:"plan_id"`
26+
ServiceID string `json:"service_id"`
27+
Parameters map[string]interface{} `json:"parameters"`
2728
}
2829

2930
var (

0 commit comments

Comments
 (0)