helper/config: can validate array configurations
This commit is contained in:
parent
72b7e2c11a
commit
35071f0328
|
@ -84,6 +84,8 @@ func (v *Validator) Validate(
|
|||
}
|
||||
|
||||
type validatorKey interface {
|
||||
// Validate validates the given configuration and returns viewed keys,
|
||||
// warnings, and errors.
|
||||
Validate(map[string]string) ([]string, []string, []error)
|
||||
}
|
||||
|
||||
|
@ -179,9 +181,11 @@ func (v *nestedValidatorKey) Validate(
|
|||
}
|
||||
|
||||
for k, _ := range m {
|
||||
if k != prefix[:len(prefix)-1] {
|
||||
if !strings.HasPrefix(k, prefix) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
used = append(used, k)
|
||||
}
|
||||
|
|
|
@ -43,6 +43,31 @@ func TestValidator(t *testing.T) {
|
|||
testInvalid(v, c)
|
||||
}
|
||||
|
||||
func TestValidator_array(t *testing.T) {
|
||||
v := &Validator{
|
||||
Required: []string{
|
||||
"foo",
|
||||
"nested.*",
|
||||
},
|
||||
}
|
||||
|
||||
var c *terraform.ResourceConfig
|
||||
|
||||
// Valid
|
||||
c = testConfig(t, map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"nested": []string{"foo", "bar"},
|
||||
})
|
||||
testValid(v, c)
|
||||
|
||||
// Not a nested structure
|
||||
c = testConfig(t, map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"nested": "baa",
|
||||
})
|
||||
testInvalid(v, c)
|
||||
}
|
||||
|
||||
func TestValidator_complex(t *testing.T) {
|
||||
v := &Validator{
|
||||
Required: []string{
|
||||
|
|
Loading…
Reference in New Issue