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

Commit

Permalink
Update src to reflect correct type name
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknelson committed Mar 28, 2018
1 parent 3df6797 commit 89f36d2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 81 deletions.
14 changes: 7 additions & 7 deletions pkg/registry/servicecatalog/clusterservicebroker/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

var (
errNotAClusterServiceBroker = errors.New("not a broker")
errNotAClusterServiceBroker = errors.New("not a clusterservicebroker")
)

// NewSingular returns a new shell of a service broker, according to the given namespace and
Expand Down Expand Up @@ -104,13 +104,13 @@ func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {

// NewStorage creates a new rest.Storage responsible for accessing
// ClusterServiceBroker resources
func NewStorage(opts server.Options) (brokers, brokersStatus rest.Storage) {
func NewStorage(opts server.Options) (clusterServiceBrokers, clusterServiceBrokerStatus rest.Storage) {
prefix := "/" + opts.ResourcePrefix()

storageInterface, dFunc := opts.GetStorage(
&servicecatalog.ClusterServiceBroker{},
prefix,
brokerRESTStrategies,
clusterServiceBrokerRESTStrategies,
NewList,
nil,
storage.NoTriggerPublisher,
Expand All @@ -130,9 +130,9 @@ func NewStorage(opts server.Options) (brokers, brokersStatus rest.Storage) {
// DefaultQualifiedResource should always be plural
DefaultQualifiedResource: servicecatalog.Resource("clusterservicebrokers"),

CreateStrategy: brokerRESTStrategies,
UpdateStrategy: brokerRESTStrategies,
DeleteStrategy: brokerRESTStrategies,
CreateStrategy: clusterServiceBrokerRESTStrategies,
UpdateStrategy: clusterServiceBrokerRESTStrategies,
DeleteStrategy: clusterServiceBrokerRESTStrategies,
EnableGarbageCollection: true,

Storage: storageInterface,
Expand All @@ -145,7 +145,7 @@ func NewStorage(opts server.Options) (brokers, brokersStatus rest.Storage) {
}

statusStore := store
statusStore.UpdateStrategy = brokerStatusUpdateStrategy
statusStore.UpdateStrategy = clusterServiceBrokerStatusUpdateStrategy

return &store, &StatusREST{&statusStore}
}
Expand Down
62 changes: 31 additions & 31 deletions pkg/registry/servicecatalog/clusterservicebroker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ import (

// NewScopeStrategy returns a new NamespaceScopedStrategy for brokers
func NewScopeStrategy() rest.NamespaceScopedStrategy {
return brokerRESTStrategies
return clusterServiceBrokerRESTStrategies
}

// implements interfaces RESTCreateStrategy, RESTUpdateStrategy, RESTDeleteStrategy,
// NamespaceScopedStrategy
type brokerRESTStrategy struct {
type clusterServiceBrokerRESTStrategy struct {
runtime.ObjectTyper // inherit ObjectKinds method
names.NameGenerator // GenerateName method for CreateStrategy
}

// implements interface RESTUpdateStrategy
type brokerStatusRESTStrategy struct {
brokerRESTStrategy
type clusterServiceBrokerStatusRESTStrategy struct {
clusterServiceBrokerRESTStrategy
}

var (
brokerRESTStrategies = brokerRESTStrategy{
clusterServiceBrokerRESTStrategies = clusterServiceBrokerRESTStrategy{
// embeds to pull in existing code behavior from upstream

// this has an interesting NOTE on it. Not sure if it applies to us.
Expand All @@ -59,35 +59,35 @@ var (
// `GenerateName(base string) string`
NameGenerator: names.SimpleNameGenerator,
}
_ rest.RESTCreateStrategy = brokerRESTStrategies
_ rest.RESTUpdateStrategy = brokerRESTStrategies
_ rest.RESTDeleteStrategy = brokerRESTStrategies
_ rest.RESTCreateStrategy = clusterServiceBrokerRESTStrategies
_ rest.RESTUpdateStrategy = clusterServiceBrokerRESTStrategies
_ rest.RESTDeleteStrategy = clusterServiceBrokerRESTStrategies

brokerStatusUpdateStrategy = brokerStatusRESTStrategy{
brokerRESTStrategies,
clusterServiceBrokerStatusUpdateStrategy = clusterServiceBrokerStatusRESTStrategy{
clusterServiceBrokerRESTStrategies,
}
_ rest.RESTUpdateStrategy = brokerStatusUpdateStrategy
_ rest.RESTUpdateStrategy = clusterServiceBrokerStatusUpdateStrategy
)

// Canonicalize does not transform a broker.
func (brokerRESTStrategy) Canonicalize(obj runtime.Object) {
func (clusterServiceBrokerRESTStrategy) Canonicalize(obj runtime.Object) {
_, ok := obj.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to create")
glog.Fatal("received a non-clusterservicebroker object to create")
}
}

// NamespaceScoped returns false as brokers are not scoped to a namespace.
func (brokerRESTStrategy) NamespaceScoped() bool {
func (clusterServiceBrokerRESTStrategy) NamespaceScoped() bool {
return false
}

// PrepareForCreate receives a the incoming ClusterServiceBroker and clears it's
// Status. Status is not a user settable field.
func (brokerRESTStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
func (clusterServiceBrokerRESTStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
broker, ok := obj.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to create")
glog.Fatal("received a non-clusterservicebroker object to create")
}
// Is there anything to pull out of the context `ctx`?

Expand All @@ -101,26 +101,26 @@ func (brokerRESTStrategy) PrepareForCreate(ctx genericapirequest.Context, obj ru
broker.Generation = 1
}

func (brokerRESTStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
func (clusterServiceBrokerRESTStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
return scv.ValidateClusterServiceBroker(obj.(*sc.ClusterServiceBroker))
}

func (brokerRESTStrategy) AllowCreateOnUpdate() bool {
func (clusterServiceBrokerRESTStrategy) AllowCreateOnUpdate() bool {
return false
}

func (brokerRESTStrategy) AllowUnconditionalUpdate() bool {
func (clusterServiceBrokerRESTStrategy) AllowUnconditionalUpdate() bool {
return false
}

func (brokerRESTStrategy) PrepareForUpdate(ctx genericapirequest.Context, new, old runtime.Object) {
func (clusterServiceBrokerRESTStrategy) PrepareForUpdate(ctx genericapirequest.Context, new, old runtime.Object) {
newClusterServiceBroker, ok := new.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to update to")
glog.Fatal("received a non-clusterservicebroker object to update to")
}
oldClusterServiceBroker, ok := old.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to update from")
glog.Fatal("received a non-clusterservicebroker object to update from")
}

newClusterServiceBroker.Status = oldClusterServiceBroker.Status
Expand All @@ -137,40 +137,40 @@ func (brokerRESTStrategy) PrepareForUpdate(ctx genericapirequest.Context, new, o
}
}

func (brokerRESTStrategy) ValidateUpdate(ctx genericapirequest.Context, new, old runtime.Object) field.ErrorList {
func (clusterServiceBrokerRESTStrategy) ValidateUpdate(ctx genericapirequest.Context, new, old runtime.Object) field.ErrorList {
newClusterServiceBroker, ok := new.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to validate to")
glog.Fatal("received a non-clusterservicebroker object to validate to")
}
oldClusterServiceBroker, ok := old.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to validate from")
glog.Fatal("received a non-clusterservicebroker object to validate from")
}

return scv.ValidateClusterServiceBrokerUpdate(newClusterServiceBroker, oldClusterServiceBroker)
}

func (brokerStatusRESTStrategy) PrepareForUpdate(ctx genericapirequest.Context, new, old runtime.Object) {
func (clusterServiceBrokerStatusRESTStrategy) PrepareForUpdate(ctx genericapirequest.Context, new, old runtime.Object) {
newClusterServiceBroker, ok := new.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to update to")
glog.Fatal("received a non-clusterservicebroker object to update to")
}
oldClusterServiceBroker, ok := old.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to update from")
glog.Fatal("received a non-clusterservicebroker object to update from")
}
// status changes are not allowed to update spec
newClusterServiceBroker.Spec = oldClusterServiceBroker.Spec
}

func (brokerStatusRESTStrategy) ValidateUpdate(ctx genericapirequest.Context, new, old runtime.Object) field.ErrorList {
func (clusterServiceBrokerStatusRESTStrategy) ValidateUpdate(ctx genericapirequest.Context, new, old runtime.Object) field.ErrorList {
newClusterServiceBroker, ok := new.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to validate to")
glog.Fatal("received a non-clusterservicebroker object to validate to")
}
oldClusterServiceBroker, ok := old.(*sc.ClusterServiceBroker)
if !ok {
glog.Fatal("received a non-broker object to validate from")
glog.Fatal("received a non-clusterservicebroker object to validate from")
}

return scv.ValidateClusterServiceBrokerStatusUpdate(newClusterServiceBroker, oldClusterServiceBroker)
Expand Down
64 changes: 32 additions & 32 deletions pkg/registry/servicecatalog/clusterservicebroker/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func brokerWithOldSpec() *sc.ClusterServiceBroker {
func clusterServiceBrokerWithOldSpec() *sc.ClusterServiceBroker {
return &sc.ClusterServiceBroker{
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
Expand All @@ -44,32 +44,32 @@ func brokerWithOldSpec() *sc.ClusterServiceBroker {
}
}

func brokerWithNewSpec() *sc.ClusterServiceBroker {
b := brokerWithOldSpec()
func clusterServiceBrokerWithNewSpec() *sc.ClusterServiceBroker {
b := clusterServiceBrokerWithOldSpec()
b.Spec.URL = "new"
return b
}

// TestClusterServiceBrokerStrategyTrivial is the testing of the trivial hardcoded
// boolean flags.
func TestClusterServiceBrokerStrategyTrivial(t *testing.T) {
if brokerRESTStrategies.NamespaceScoped() {
t.Errorf("broker create must not be namespace scoped")
if clusterServiceBrokerRESTStrategies.NamespaceScoped() {
t.Errorf("clusterservicebroker create must not be namespace scoped")
}
if brokerRESTStrategies.NamespaceScoped() {
t.Errorf("broker update must not be namespace scoped")
if clusterServiceBrokerRESTStrategies.NamespaceScoped() {
t.Errorf("clusterservicebroker update must not be namespace scoped")
}
if brokerRESTStrategies.AllowCreateOnUpdate() {
t.Errorf("broker should not allow create on update")
if clusterServiceBrokerRESTStrategies.AllowCreateOnUpdate() {
t.Errorf("clusterservicebroker should not allow create on update")
}
if brokerRESTStrategies.AllowUnconditionalUpdate() {
t.Errorf("broker should not allow unconditional update")
if clusterServiceBrokerRESTStrategies.AllowUnconditionalUpdate() {
t.Errorf("clusterservicebroker should not allow unconditional update")
}
}

// TestBrokerCreate
func TestBroker(t *testing.T) {
// Create a broker or brokers
// TestClusterServiceBrokerCreate
func TestClusterServiceBroker(t *testing.T) {
// Create a clusterservicebroker or clusterservicebrokers
broker := &sc.ClusterServiceBroker{
Spec: sc.ClusterServiceBrokerSpec{
CommonServiceBrokerSpec: sc.CommonServiceBrokerSpec{
Expand All @@ -82,19 +82,19 @@ func TestBroker(t *testing.T) {
}

// Canonicalize the broker
brokerRESTStrategies.PrepareForCreate(nil, broker)
clusterServiceBrokerRESTStrategies.PrepareForCreate(nil, broker)

if broker.Status.Conditions == nil {
t.Fatalf("Fresh broker should have empty status")
t.Fatalf("Fresh clusterservicebroker should have empty status")
}
if len(broker.Status.Conditions) != 0 {
t.Fatalf("Fresh broker should have empty status")
t.Fatalf("Fresh clusterservicebroker should have empty status")
}
}

// TestBrokerUpdate tests that generation is incremented correctly when the
// spec of a Broker is updated.
func TestBrokerUpdate(t *testing.T) {
// TestClusterServiceBrokerUpdate tests that generation is incremented
// correctly when the spec of a ClusterServiceBroker is updated.
func TestClusterServiceBrokerUpdate(t *testing.T) {
cases := []struct {
name string
older *sc.ClusterServiceBroker
Expand All @@ -103,20 +103,20 @@ func TestBrokerUpdate(t *testing.T) {
}{
{
name: "no spec change",
older: brokerWithOldSpec(),
newer: brokerWithOldSpec(),
older: clusterServiceBrokerWithOldSpec(),
newer: clusterServiceBrokerWithOldSpec(),
shouldGenerationIncrement: false,
},
{
name: "spec change",
older: brokerWithOldSpec(),
newer: brokerWithNewSpec(),
older: clusterServiceBrokerWithOldSpec(),
newer: clusterServiceBrokerWithNewSpec(),
shouldGenerationIncrement: true,
},
}

for i := range cases {
brokerRESTStrategies.PrepareForUpdate(nil, cases[i].newer, cases[i].older)
clusterServiceBrokerRESTStrategies.PrepareForUpdate(nil, cases[i].newer, cases[i].older)

if cases[i].shouldGenerationIncrement {
if e, a := cases[i].older.Generation+1, cases[i].newer.Generation; e != a {
Expand All @@ -130,9 +130,9 @@ func TestBrokerUpdate(t *testing.T) {
}
}

// TestBrokerUpdateForRelistRequests tests that the RelistRequests field is
// TestClusterServiceBrokerUpdateForRelistRequests tests that the RelistRequests field is
// ignored during updates when it is the default value.
func TestBrokerUpdateForRelistRequests(t *testing.T) {
func TestClusterServiceBrokerUpdateForRelistRequests(t *testing.T) {
cases := []struct {
name string
oldValue int64
Expand Down Expand Up @@ -165,15 +165,15 @@ func TestBrokerUpdateForRelistRequests(t *testing.T) {
},
}
for _, tc := range cases {
oldBroker := brokerWithOldSpec()
oldBroker := clusterServiceBrokerWithOldSpec()
oldBroker.Spec.RelistRequests = tc.oldValue

newBroker := brokerWithOldSpec()
newBroker.Spec.RelistRequests = tc.newValue
newClusterServiceBroker := clusterServiceBrokerWithOldSpec()
newClusterServiceBroker.Spec.RelistRequests = tc.newValue

brokerRESTStrategies.PrepareForUpdate(nil, newBroker, oldBroker)
clusterServiceBrokerRESTStrategies.PrepareForUpdate(nil, newClusterServiceBroker, oldBroker)

if e, a := tc.expectedValue, newBroker.Spec.RelistRequests; e != a {
if e, a := tc.expectedValue, newClusterServiceBroker.Spec.RelistRequests; e != a {
t.Errorf("%s: got unexpected RelistRequests: expected %v, got %v", tc.name, e, a)
}
}
Expand Down
Loading

0 comments on commit 89f36d2

Please sign in to comment.