Skip to content

Commit

Permalink
Validate that a ServiceClass must have at least one plan (openshift#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie authored and Ville Aikas committed May 25, 2017
1 parent 9db9fa4 commit 7295dad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/servicecatalog/validation/serviceclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func ValidateServiceClass(serviceclass *sc.ServiceClass) field.ErrorList {
allErrs = append(allErrs, field.Invalid(field.NewPath("externalID"), serviceclass.ExternalID, msg))
}

if len(serviceclass.Plans) < 1 {
allErrs = append(allErrs, field.Invalid(field.NewPath("plans"), serviceclass.Plans, "at least one plan is required"))
}

planNames := sets.NewString()
for i, plan := range serviceclass.Plans {
planPath := field.NewPath("plans").Index(i)
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/servicecatalog/validation/serviceclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ func TestValidateServiceClass(t *testing.T) {
}(),
valid: false,
},
{
name: "invalid serviceClass - no plans",
serviceClass: func() *servicecatalog.ServiceClass {
s := validServiceClass()
s.Plans = nil
return s
}(),
valid: false,
},
}

for _, tc := range cases {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/clientset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ func testServiceClassClient(sType server.StorageType, client servicecatalogclien
Bindable: true,
ExternalID: "b8269ab4-7d2d-456d-8c8b-5aab63b321d1",
Description: "test description",
Plans: []v1alpha1.ServicePlan{
{
Name: "test-service-plan",
ExternalID: "test-service-plan-external-id",
Description: "test-description",
},
},
}

// start from scratch
Expand Down

0 comments on commit 7295dad

Please sign in to comment.