helper/config: more correct logic with regards to nested things
This commit is contained in:
parent
dbe5a1254a
commit
0b2860fafc
|
@ -145,7 +145,7 @@ func (v *nestedValidatorKey) Validate(
|
|||
m map[string]string) ([]string, []string, []error) {
|
||||
countStr, ok := m[v.Prefix+".#"]
|
||||
if !ok {
|
||||
if !v.Required {
|
||||
if !v.Required || v.Key != "" {
|
||||
// Not present, that is okay
|
||||
return nil, nil, nil
|
||||
} else {
|
||||
|
|
|
@ -70,6 +70,39 @@ func TestValidator_complex(t *testing.T) {
|
|||
testInvalid(v, c)
|
||||
}
|
||||
|
||||
func TestValidator_complexDeepRequired(t *testing.T) {
|
||||
v := &Validator{
|
||||
Required: []string{
|
||||
"foo",
|
||||
"nested.*.foo",
|
||||
},
|
||||
}
|
||||
|
||||
var c *terraform.ResourceConfig
|
||||
|
||||
// Valid
|
||||
c = testConfig(t, map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"nested": []map[string]interface{}{
|
||||
map[string]interface{}{"foo": "bar"},
|
||||
},
|
||||
})
|
||||
testValid(v, c)
|
||||
|
||||
// Valid
|
||||
c = testConfig(t, map[string]interface{}{
|
||||
"foo": "bar",
|
||||
})
|
||||
testValid(v, c)
|
||||
|
||||
// Not a nested structure
|
||||
c = testConfig(t, map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"nested": "baa",
|
||||
})
|
||||
testInvalid(v, c)
|
||||
}
|
||||
|
||||
func testConfig(
|
||||
t *testing.T,
|
||||
c map[string]interface{}) *terraform.ResourceConfig {
|
||||
|
@ -97,6 +130,10 @@ func testValid(v *Validator, c *terraform.ResourceConfig) {
|
|||
panic(fmt.Sprintf("bad: %#v", ws))
|
||||
}
|
||||
if len(es) > 0 {
|
||||
panic(fmt.Sprintf("bad: %#v", es))
|
||||
estrs := make([]string, len(es))
|
||||
for i, e := range es {
|
||||
estrs[i] = e.Error()
|
||||
}
|
||||
panic(fmt.Sprintf("bad: %#v", estrs))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue