mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Adjust testing for server-side validation as default
This commit is contained in:
parent
36dbecd438
commit
d815449ae5
@ -1075,7 +1075,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("should create/apply a valid CR with arbitrary-extra properties for CRD with partially-specified validation schema", func() {
|
ginkgo.It("should create/apply an invalid/valid CR with arbitrary-extra properties for CRD with partially-specified validation schema", func() {
|
||||||
ginkgo.By("prepare CRD with partially-specified validation schema")
|
ginkgo.By("prepare CRD with partially-specified validation schema")
|
||||||
crd, err := crd.CreateTestCRD(f, func(crd *apiextensionsv1.CustomResourceDefinition) {
|
crd, err := crd.CreateTestCRD(f, func(crd *apiextensionsv1.CustomResourceDefinition) {
|
||||||
props := &apiextensionsv1.JSONSchemaProps{}
|
props := &apiextensionsv1.JSONSchemaProps{}
|
||||||
@ -1101,6 +1101,15 @@ metadata:
|
|||||||
|
|
||||||
meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-cr")
|
meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-cr")
|
||||||
|
|
||||||
|
// XPreserveUnknownFields is defined on the root of the schema so unknown fields within the spec
|
||||||
|
// are still considered invalid
|
||||||
|
invalidArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}],"extraProperty":"arbitrary-value"}}`, meta)
|
||||||
|
err = createApplyCustomResource(invalidArbitraryCR, f.Namespace.Name, "test-cr", crd)
|
||||||
|
framework.ExpectError(err, "creating custom resource")
|
||||||
|
if !strings.Contains(err.Error(), `unknown field "spec.extraProperty"`) {
|
||||||
|
framework.Failf("incorrect error from createApplyCustomResource: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// unknown fields on the root are considered valid
|
// unknown fields on the root are considered valid
|
||||||
validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}]},"extraProperty":"arbitrary-value"}`, meta)
|
validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}]},"extraProperty":"arbitrary-value"}`, meta)
|
||||||
err = createApplyCustomResource(validArbitraryCR, f.Namespace.Name, "test-cr", crd)
|
err = createApplyCustomResource(validArbitraryCR, f.Namespace.Name, "test-cr", crd)
|
||||||
|
Loading…
Reference in New Issue
Block a user