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

Add asynchronous provisioning test using the fake broker server #923

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1000 to where you're going here, see #514


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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these should have some indication in the name that they are the Test constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MHBauer I argue that they already do when used externally to this package. Recall that the package name will come first, so this specific constant will be referenced as fake.InstanceGUID

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that the name of the package carries the meaning. I suggest we call this package 'testfixtures', though, since the code here is not really a 'fake'.

)
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these functions exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

various fields need to store *bools, and this is a convenience function to create them with a one-liner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having never actually tried it, I tried it, and apparently you can't take the address of a bool. Bizzare language.

Would it be better to have it once in a toplevel util package than rewriting this in a multiple places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen truePtr and falsePtr around somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that would be nice, but out of the scope of this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, those are hanging around. We'll probably want to move them here naturally at some point.

}
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