From a1e86125d833eb9f5c038dd7ff8ceaefa6800cb9 Mon Sep 17 00:00:00 2001 From: Sam Gunaratne Date: Wed, 21 Jun 2017 10:33:15 +0100 Subject: [PATCH] Add Service Broker Schema tests 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 https://github.com/openservicebrokerapi/servicebroker/issues/59 and https://github.com/cloudfoundry/cloud_controller_ng/pull/834 --- assets/service_broker/cats.json | 3 ++- helpers/services/broker.go | 27 +++++++++++++++++++++++---- services/service_broker_lifecycle.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/assets/service_broker/cats.json b/assets/service_broker/cats.json index 8b7300ef7..80e1dfdda 100644 --- a/assets/service_broker/cats.json +++ b/assets/service_broker/cats.json @@ -51,7 +51,8 @@ "content": "40 concurrent connections" } ] - } + }, + "schemas": "" }, { "name": "", diff --git a/helpers/services/broker.go b/helpers/services/broker.go index c8d81a3b9..41f45fe8a 100644 --- a/helpers/services/broker.go +++ b/helpers/services/broker.go @@ -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 { @@ -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 @@ -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")}, @@ -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( "", b.Service.Name, "", b.Service.ID, @@ -181,6 +199,7 @@ func (b ServiceBroker) ToJSON() string { "", b.AsyncPlans[0].ID, "", b.AsyncPlans[1].Name, "", b.AsyncPlans[1].ID, + "\"\"", string(planSchema), ) return replacer.Replace(string(bytes)) diff --git a/services/service_broker_lifecycle.go b/services/service_broker_lifecycle.go index 466350381..71867d42b 100644 --- a/services/service_broker_lifecycle.go +++ b/services/service_broker_lifecycle.go @@ -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() @@ -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()