add e2e test for enforcing enums in schema.

This commit is contained in:
Jiahui Feng 2021-11-15 09:10:43 -08:00
parent a8175212aa
commit 52d8b53663

View File

@ -87,6 +87,12 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
framework.Failf("failed to delete valid CR: %v", err)
}
ginkgo.By("client-side validation (kubectl create and apply) rejects request with value outside defined enum values")
badEnumValueCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar", "feeling":"NonExistentValue"}]}}`, meta)
if _, err := framework.RunKubectlInput(f.Namespace.Name, badEnumValueCR, ns, "create", "-f", "-"); err == nil || !strings.Contains(err.Error(), `Unsupported value: "NonExistentValue"`) {
framework.Failf("unexpected no error when creating CR with unknown enum value: %v", err)
}
ginkgo.By("client-side validation (kubectl create and apply) rejects request with unknown properties when disallowed by the schema")
unknownCR := fmt.Sprintf(`{%s,"spec":{"foo":true}}`, meta)
if _, err := framework.RunKubectlInput(f.Namespace.Name, unknownCR, ns, "create", "-f", "-"); err == nil || !strings.Contains(err.Error(), `unknown field "foo"`) {
@ -741,6 +747,12 @@ properties:
age:
description: Age of Bar.
type: string
feeling:
description: Whether Bar is feeling great.
type: string
enum:
- Great
- Down
bazs:
description: List of Bazs.
items: