Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Add Service Broker Schema tests
Browse files Browse the repository at this point in the history
Service brokers may now define JSON schema as part of the catalog
endpoint. This will be offered on through CAPI and consumed by client
tooling.

See openservicebrokerapi/servicebroker#59
and cloudfoundry/cloud_controller_ng#834
  • Loading branch information
Samze authored and Pivotal committed Jul 21, 2017
1 parent e24395a commit a1e8612
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
3 changes: 2 additions & 1 deletion assets/service_broker/cats.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"content": "40 concurrent connections"
}
]
}
},
"schemas": "<fake-plan-schema>"
},
{
"name": "<fake-plan-2>",
Expand Down
27 changes: 23 additions & 4 deletions helpers/services/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ import (
)

type Plan struct {
Name string `json:"name"`
ID string `json:"id"`
Name string `json:"name"`
ID string `json:"id"`
Schemas PlanSchemas `json:"schemas"`
}

type PlanSchemas struct {
ServiceInstance struct {
Create struct {
Parameters map[string]interface{} `json:"parameters"`
} `json:"create"`
} `json:"service_instance"`
}

type ServiceBroker struct {
Expand Down Expand Up @@ -54,10 +63,15 @@ type ServiceResponse struct {
}
}

type ServicePlansResponse struct {
Resources []ServicePlanResponse
}

type ServicePlanResponse struct {
Entity struct {
Name string
Public bool
Name string
Public bool
Schemas PlanSchemas
}
Metadata struct {
Url string
Expand Down Expand Up @@ -89,6 +103,7 @@ func NewServiceBroker(name string, path string, TestSetup *workflowhelpers.Repro
b.Name = name
b.Service.Name = random_name.CATSRandomName("SVC")
b.Service.ID = random_name.CATSRandomName("SVC-ID")

b.SyncPlans = []Plan{
{Name: random_name.CATSRandomName("SVC-PLAN"), ID: random_name.CATSRandomName("SVC-PLAN-ID")},
{Name: random_name.CATSRandomName("SVC-PLAN"), ID: random_name.CATSRandomName("SVC-PLAN-ID")},
Expand Down Expand Up @@ -167,6 +182,9 @@ func (b ServiceBroker) ToJSON() string {
bytes, err := ioutil.ReadFile(assets.NewAssets().ServiceBroker + "/cats.json")
Expect(err).To(BeNil())

planSchema, err := json.Marshal(b.SyncPlans[0].Schemas)
Expect(err).To(BeNil())

replacer := strings.NewReplacer(
"<fake-service>", b.Service.Name,
"<fake-service-guid>", b.Service.ID,
Expand All @@ -181,6 +199,7 @@ func (b ServiceBroker) ToJSON() string {
"<fake-async-plan-guid>", b.AsyncPlans[0].ID,
"<fake-async-plan-2>", b.AsyncPlans[1].Name,
"<fake-async-plan-2-guid>", b.AsyncPlans[1].ID,
"\"<fake-plan-schema>\"", string(planSchema),
)

return replacer.Replace(string(bytes))
Expand Down
28 changes: 28 additions & 0 deletions services/service_broker_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,31 @@ var _ = ServicesDescribe("Service Broker Lifecycle", func() {
Expect(plans).To(Say(broker.SyncPlans[0].Name))
Expect(plans).To(Say(broker.SyncPlans[1].Name))

// Confirm default schemas show up in CAPI
cfResponse := cf.Cf("curl", fmt.Sprintf("/v2/service_plans?q=unique_id:%s", broker.SyncPlans[0].ID)).
Wait(Config.DefaultTimeoutDuration()).Out.Contents()

var plansResponse ServicePlansResponse
err := json.Unmarshal(cfResponse, &plansResponse)
Expect(err).To(BeNil())

var emptySchemas PlanSchemas
emptySchemas.ServiceInstance.Create.Parameters = map[string]interface{}{}

Expect(plansResponse.Resources[0].Entity.Schemas).To(Equal(emptySchemas))

// Changing the catalog on the broker
oldServiceName = broker.Service.Name
oldPlanName = broker.SyncPlans[0].Name
broker.Service.Name = random_name.CATSRandomName("SVC")
broker.SyncPlans[0].Name = random_name.CATSRandomName("SVC-PLAN")

var basicSchema PlanSchemas
basicSchema.ServiceInstance.Create.Parameters = map[string]interface{}{
"$schema": "http://example.com/broker/schema", "type": "object",
}
broker.SyncPlans[0].Schemas = basicSchema

broker.Configure()
broker.Update()

Expand All @@ -75,6 +95,14 @@ var _ = ServicesDescribe("Service Broker Lifecycle", func() {
Expect(plans).To(Say(broker.Service.Name))
Expect(plans).To(Say(broker.Plans()[0].Name))

// Confirm plan schemas show up in CAPI
cfResponse = cf.Cf("curl", fmt.Sprintf("/v2/service_plans?q=unique_id:%s", broker.SyncPlans[0].ID)).
Wait(Config.DefaultTimeoutDuration()).Out.Contents()

err = json.Unmarshal(cfResponse, &plansResponse)
Expect(err).To(BeNil())
Expect(plansResponse.Resources[0].Entity.Schemas).To(Equal(broker.SyncPlans[0].Schemas))

// Deleting the service broker and confirming the plans no longer display
workflowhelpers.AsUser(TestSetup.AdminUserContext(), TestSetup.ShortTimeout(), func() {
broker.Delete()
Expand Down

0 comments on commit a1e8612

Please sign in to comment.