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

Tests for filter.go and comments in types.go #2055

Merged
merged 9 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 6 additions & 4 deletions pkg/apis/servicecatalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ type CommonServiceBrokerSpec struct {
//
// ServiceClass allowed property names:
// name - the value set to [Cluster]ServiceClass.Name
// externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName
//
// spec.externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName
// spec.externalID - the value set to [Cluster]ServiceClass.Spec.ExternalID
// ServicePlan allowed property names:
// name - the value set to [Cluster]ServiceClass.Name
// externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName
// name - the value set to [Cluster]ServicePlan.Name
// spec.externalName - the value set to [Cluster]ServicePlan.Spec.ExternalName
// spec.externalID - the value set to [Cluster]ServicePlan.Spec.ExternalID
// spec.serviceClassName - the value set to [Cluster]ServicePlan.Spec.ServiceClassRef.Name
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments apply to here from the other types file

type CatalogRestrictions struct {
// ServiceClass represents a selector for plans, used to filter catalog re-lists.
ServicePlan []string
Expand Down
93 changes: 90 additions & 3 deletions pkg/apis/servicecatalog/v1beta1/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,93 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestConvertServiceClassToProperties(t *testing.T) {
cases := []struct {
name string
sc *ServiceClass
json string
}{
{
name: "nil object",
json: "{}",
},
{
name: "normal object",
sc: &ServiceClass{
ObjectMeta: metav1.ObjectMeta{Name: "service-class"},
Spec: ServiceClassSpec{
CommonServiceClassSpec: CommonServiceClassSpec{
ExternalName: "external-class-name",
ExternalID: "external-id",
},
},
},
json: `{"name":"service-class","spec.externalID":"external-id","spec.externalName":"external-class-name"}`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
p := ConvertServiceClassToProperties(tc.sc)
if p == nil {
t.Fatalf("Failed to create Properties object from %+v", tc.sc)
}
b, err := json.Marshal(p)
if err != nil {
t.Fatalf("Unexpected error with json marshal, %v", err)
}
js := string(b)
if js != tc.json {
t.Fatalf("Failed to create expected Properties object,\n\texpected: \t%q,\n \tgot: \t\t%q", tc.json, js)
}
})
}
}

func TestConvertServicePlanToProperties(t *testing.T) {
cases := []struct {
name string
sp *ServicePlan
json string
}{
{
name: "nil object",
json: "{}",
},
{
name: "normal object",
sp: &ServicePlan{
ObjectMeta: metav1.ObjectMeta{Name: "service-plan"},
Spec: ServicePlanSpec{
CommonServicePlanSpec: CommonServicePlanSpec{
ExternalName: "external-plan-name",
ExternalID: "external-id",
},
ServiceClassRef: LocalObjectReference{
Name: "service-class-name",
},
},
},
json: `{"name":"service-plan","spec.externalID":"external-id","spec.externalName":"external-plan-name","spec.serviceClassName":"service-class-name"}`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
p := ConvertServicePlanToProperties(tc.sp)
if p == nil {
t.Fatalf("Failed to create Properties object from %+v", tc.sp)
}
b, err := json.Marshal(p)
if err != nil {
t.Fatalf("Unexpected error with json marshal, %v", err)
}
js := string(b)
if js != tc.json {
t.Fatalf("Failed to create expected Properties object,\n\texpected: \t%q,\n \tgot: \t\t%q", tc.json, js)
}
})
}
}

func TestConvertClusterServiceClassToProperties(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -55,7 +142,7 @@ func TestConvertClusterServiceClassToProperties(t *testing.T) {
}
b, err := json.Marshal(p)
if err != nil {
t.Fatalf("Unexpected error with json marchal, %v", err)
t.Fatalf("Unexpected error with json marshal, %v", err)
}
js := string(b)
if js != tc.json {
Expand Down Expand Up @@ -89,7 +176,7 @@ func TestConvertClusterServicePlanToProperties(t *testing.T) {
},
},
},
json: `{"name":"service-plan","spec.clusterServiceClass.name":"cluster-service-class-name","spec.externalID":"external-id","spec.externalName":"external-plan-name"}`,
json: `{"name":"service-plan","spec.clusterServiceClassName":"cluster-service-class-name","spec.externalID":"external-id","spec.externalName":"external-plan-name"}`,
},
}
for _, tc := range cases {
Expand All @@ -100,7 +187,7 @@ func TestConvertClusterServicePlanToProperties(t *testing.T) {
}
b, err := json.Marshal(p)
if err != nil {
t.Fatalf("Unexpected error with json marchal, %v", err)
t.Fatalf("Unexpected error with json marshal, %v", err)
}
js := string(b)
if js != tc.json {
Expand Down
14 changes: 8 additions & 6 deletions pkg/apis/servicecatalog/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ type CommonServiceBrokerSpec struct {
//
// ServiceClass allowed property names:
// name - the value set to [Cluster]ServiceClass.Name
// externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName
//
// spec.externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName
// spec.externalID - the value set to [Cluster]ServiceClass.Spec.ExternalID
// ServicePlan allowed property names:
// name - the value set to [Cluster]ServiceClass.Name
// externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName
// name - the value set to [Cluster]ServicePlan.Name
// spec.externalName - the value set to [Cluster]ServicePlan.Spec.ExternalName
// spec.externalID - the value set to [Cluster]ServicePlan.Spec.ExternalID
// spec.serviceClassName - the value set to [Cluster]ServicePlan.Spec.ServiceClassRef.Name
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this line to:

//   spec.serviceClass.name - the value set to ServicePlan.Spec.ServiceClassRef.Name
//   spec.clusterServiceClass.name - the value set to ClusterServicePlan.Spec.ClusterServiceClassRef.Name

type CatalogRestrictions struct {
// ServiceClass represents a selector for plans, used to filter catalog re-lists.
ServiceClass []string `json:"serviceClass,omitempty"`
Expand Down Expand Up @@ -1314,9 +1316,9 @@ const (
// SpecServiceBrokerName is used for ServiceClasses, the parent service broker name.
FilterSpecServiceBrokerName = "spec.serviceBrokerName"
// SpecClusterServiceClassName is only used for plans, the parent service class name.
FilterSpecClusterServiceClassName = "spec.clusterServiceClass.name"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please undo this change

FilterSpecClusterServiceClassName = "spec.clusterServiceClassName"
// SpecServiceClassName is only used for plans, the parent service class name.
FilterSpecServiceClassName = "spec.serviceClass.name"
Copy link
Contributor

Choose a reason for hiding this comment

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

And undo this change.

FilterSpecServiceClassName = "spec.serviceClassName"
)

// SecretTransform is a single transformation that is applied to the
Expand Down
2 changes: 1 addition & 1 deletion pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.