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

Commit

Permalink
Add asynchronous provisioning test using the fake broker server
Browse files Browse the repository at this point in the history
  • Loading branch information
arschles committed Jul 10, 2017
1 parent 39a1061 commit 8f6dc37
Show file tree
Hide file tree
Showing 17 changed files with 1,045 additions and 337 deletions.
47 changes: 47 additions & 0 deletions pkg/apis/servicecatalog/fake/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fake

const (
// Namespace is a name used for test namespaces
Namespace = "test-ns"
// NamespaceUID is a UID used for test namespaces
NamespaceUID = "test-ns-uid"

// BrokerURL is the URL used for test brokers
BrokerURL = "http://example.com"
// BrokerName is the name used for test brokers
BrokerName = "test-broker"

// ServiceClassName is the name used for test service classes
ServiceClassName = "test-serviceclass"
// ServiceClassGUID is the GUID used for test service classes
ServiceClassGUID = "SCGUID"
// PlanName is the name used for test plans
PlanName = "test-plan"
// PlanGUID is the GUID used for test plans
PlanGUID = "PGUID"
//NonBindablePlanName is the name used for test plans that should not be bindable
NonBindablePlanName = "test-unbindable-plan"
// NonBindablePlanGUID is the GUID used for test plans that should not be bindable
NonBindablePlanGUID = "UNBINDABLE-PLAN"

// InstanceName is a name used for test instances
InstanceName = "test-instance"
// InstanceGUID is the GUID used for test instances
InstanceGUID = "IGUID"
)
21 changes: 21 additions & 0 deletions pkg/apis/servicecatalog/fake/pointers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fake

func boolPtr(b bool) *bool {
return &b
}
71 changes: 71 additions & 0 deletions pkg/apis/servicecatalog/fake/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fake

import (
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GetBroker is a convenience function to get a *v1alpha1.Broker for use in tests
func GetBroker() *v1alpha1.Broker {
return &v1alpha1.Broker{
ObjectMeta: metav1.ObjectMeta{Name: BrokerName},
Spec: v1alpha1.BrokerSpec{
URL: BrokerURL,
},
}
}

// GetServiceClass returns a ServiceClass that can be used by tests
func GetServiceClass() *v1alpha1.ServiceClass {
return &v1alpha1.ServiceClass{
ObjectMeta: metav1.ObjectMeta{Name: ServiceClassName},
BrokerName: BrokerName,
Description: "a test service",
ExternalID: ServiceClassGUID,
Bindable: true,
Plans: []v1alpha1.ServicePlan{
{
Name: PlanName,
Description: "a test plan",
Free: true,
ExternalID: PlanGUID,
},
{
Name: NonBindablePlanName,
Description: "a test plan",
Free: true,
ExternalID: NonBindablePlanGUID,
Bindable: boolPtr(false),
},
},
}

}

// GetInstance returns an Instance that can be used by tests
func GetInstance() *v1alpha1.Instance {
return &v1alpha1.Instance{
ObjectMeta: metav1.ObjectMeta{Name: InstanceName, Namespace: Namespace},
Spec: v1alpha1.InstanceSpec{
ServiceClassName: ServiceClassName,
PlanName: PlanName,
ExternalID: InstanceGUID,
},
}
}
69 changes: 69 additions & 0 deletions pkg/brokerapi/fake/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fake

import (
osb "github.com/pmorie/go-open-service-broker-client/v2"
)

const (
// ServiceClassName is the static name for service classes in test data
ServiceClassName = "testserviceclass"
// ServiceClassGUID is the static guid for service classes in test data
ServiceClassGUID = "testserviceclassGUID"
// PlanName is the static name for plans in test data
PlanName = "testplan"
// PlanGUID is the static name for plan GUIDs in test data
PlanGUID = "testPlanGUID"
// NonBindablePlanName is the static name for non-bindable plans in test data
NonBindablePlanName = "testNonBindablePlan"
// NonBindablePlanGUID is the static GUID for non-bindable plans in test data
NonBindablePlanGUID = "testNonBinablePlanGUID"
)

func boolPtr(b bool) *bool {
return &b
}

// GetTestCatalog returns a static osb.CatalogResponse for use in testing
func GetTestCatalog() *osb.CatalogResponse {
return &osb.CatalogResponse{
Services: []osb.Service{
{
Name: ServiceClassName,
ID: ServiceClassGUID,
Description: "a test service",
Bindable: true,
Plans: []osb.Plan{
{
Name: PlanName,
Free: boolPtr(true),
ID: PlanGUID,
Description: "a test plan",
},
{
Name: NonBindablePlanName,
Free: boolPtr(true),
ID: NonBindablePlanGUID,
Description: "a test plan",
Bindable: boolPtr(false),
},
},
},
},
}
}
17 changes: 11 additions & 6 deletions pkg/brokerapi/fake/server/convert_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,46 @@ limitations under the License.
package server

import (
pkgbrokerapi "github.com/kubernetes-incubator/service-catalog/pkg/brokerapi"
pivbrokerapi "github.com/pivotal-cf/brokerapi"
osb "github.com/pmorie/go-open-service-broker-client/v2"
)

// ConvertCatalog converts a (github.com/kubernetes-incubator/service-catalog/pkg/brokerapi).Catalog
// to an array of brokerapi.Services
func ConvertCatalog(cat *pkgbrokerapi.Catalog) []pivbrokerapi.Service {
func ConvertCatalog(cat *osb.CatalogResponse) []pivbrokerapi.Service {
ret := make([]pivbrokerapi.Service, len(cat.Services))
for i, svc := range cat.Services {
ret[i] = convertService(svc)
}
return ret
}

func convertService(svc *pkgbrokerapi.Service) pivbrokerapi.Service {
func convertService(svc osb.Service) pivbrokerapi.Service {
updateable := false
if svc.PlanUpdatable != nil {
updateable = *svc.PlanUpdatable
}
return pivbrokerapi.Service{
ID: svc.ID,
Name: svc.Name,
Description: svc.Description,
Bindable: svc.Bindable,
Tags: svc.Tags,
PlanUpdatable: svc.PlanUpdateable,
PlanUpdatable: updateable,
Plans: convertPlans(svc.Plans),
// TODO: convert Requires, Metadata, DashboardClient
}
}

func convertPlans(plans []pkgbrokerapi.ServicePlan) []pivbrokerapi.ServicePlan {
func convertPlans(plans []osb.Plan) []pivbrokerapi.ServicePlan {
ret := make([]pivbrokerapi.ServicePlan, len(plans))
for i, plan := range plans {

ret[i] = pivbrokerapi.ServicePlan{
ID: plan.ID,
Name: plan.Name,
Description: plan.Description,
Free: &plan.Free,
Free: plan.Free,
Bindable: plan.Bindable,
// TODO: convert Metadata
}
Expand Down
Loading

0 comments on commit 8f6dc37

Please sign in to comment.