apiextensions: add invalid validation schema regex test

This commit is contained in:
Dr. Stefan Schimanski 2019-05-28 22:52:48 +02:00
parent 6d70e7ff01
commit ba5c9b492e

View File

@ -139,7 +139,7 @@ func convertNullTypeToNullable(x interface{}) interface{} {
} }
} }
func TestNullable(t *testing.T) { func TestValidateCustomResource(t *testing.T) {
type args struct { type args struct {
schema apiextensions.JSONSchemaProps schema apiextensions.JSONSchemaProps
object interface{} object interface{}
@ -149,6 +149,7 @@ func TestNullable(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
// TODO: make more complete
{"!nullable against non-null", args{ {"!nullable against non-null", args{
apiextensions.JSONSchemaProps{ apiextensions.JSONSchemaProps{
Properties: map[string]apiextensions.JSONSchemaProps{ Properties: map[string]apiextensions.JSONSchemaProps{
@ -235,6 +236,17 @@ func TestNullable(t *testing.T) {
}, },
map[string]interface{}{"field": nil}, map[string]interface{}{"field": nil},
}, false}, }, false},
{"invalid regex", args{
apiextensions.JSONSchemaProps{
Properties: map[string]apiextensions.JSONSchemaProps{
"field": {
Type: "string",
Pattern: "+",
},
},
},
map[string]interface{}{"field": "foo"},
}, true},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {