mirror of https://github.com/databricks/cli.git
Fix pattern validation for input properties (#912)
## Changes Fixes bug where input validation would only be done on the first input parameter in the template schema. ## Tests Unit test.
This commit is contained in:
parent
3411b8aa37
commit
f8d7e31118
|
@ -122,7 +122,10 @@ func (s *Schema) validatePattern(instance map[string]any) error {
|
|||
if !ok {
|
||||
continue
|
||||
}
|
||||
return ValidatePatternMatch(k, v, fieldInfo)
|
||||
err := ValidatePatternMatch(k, v, fieldInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -193,3 +193,32 @@ func TestValidateInstancePatternWithCustomMessage(t *testing.T) {
|
|||
assert.EqualError(t, schema.validatePattern(invalidInstanceValue), "invalid value for foo: \"xyz\". Please enter a string starting with 'a' and ending with 'c'")
|
||||
assert.EqualError(t, schema.ValidateInstance(invalidInstanceValue), "invalid value for foo: \"xyz\". Please enter a string starting with 'a' and ending with 'c'")
|
||||
}
|
||||
|
||||
func TestValidateInstanceForMultiplePatterns(t *testing.T) {
|
||||
schema, err := Load("./testdata/instance-validate/multiple-patterns-schema.json")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Valid values for both foo and bar
|
||||
validInstance := map[string]any{
|
||||
"foo": "abcc",
|
||||
"bar": "deff",
|
||||
}
|
||||
assert.NoError(t, schema.validatePattern(validInstance))
|
||||
assert.NoError(t, schema.ValidateInstance(validInstance))
|
||||
|
||||
// Valid value for bar, invalid value for foo
|
||||
invalidInstanceValue := map[string]any{
|
||||
"foo": "xyz",
|
||||
"bar": "deff",
|
||||
}
|
||||
assert.EqualError(t, schema.validatePattern(invalidInstanceValue), "invalid value for foo: \"xyz\". Expected to match regex pattern: ^[a-c]+$")
|
||||
assert.EqualError(t, schema.ValidateInstance(invalidInstanceValue), "invalid value for foo: \"xyz\". Expected to match regex pattern: ^[a-c]+$")
|
||||
|
||||
// Valid value for foo, invalid value for bar
|
||||
invalidInstanceValue = map[string]any{
|
||||
"foo": "abcc",
|
||||
"bar": "xyz",
|
||||
}
|
||||
assert.EqualError(t, schema.validatePattern(invalidInstanceValue), "invalid value for bar: \"xyz\". Expected to match regex pattern: ^[d-f]+$")
|
||||
assert.EqualError(t, schema.ValidateInstance(invalidInstanceValue), "invalid value for bar: \"xyz\". Expected to match regex pattern: ^[d-f]+$")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-c]+$"
|
||||
},
|
||||
"bar": {
|
||||
"type": "string",
|
||||
"pattern": "^[d-f]+$"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue