helper/schema: properly validate sub-resources

This commit is contained in:
Mitchell Hashimoto 2014-08-17 14:33:54 -07:00
parent c3f1f49640
commit a33e4bcdf0
2 changed files with 40 additions and 0 deletions

View File

@ -76,6 +76,10 @@ func (r *Resource) InternalValidate() error {
}
switch t := v.Elem.(type) {
case *Resource:
if err := t.InternalValidate(); err != nil {
return err
}
case *Schema:
bad := t.Computed || t.Optional || t.Required
if bad {

View File

@ -108,6 +108,42 @@ func TestResourceInternalValidate(t *testing.T) {
},
true,
},
// Sub-resource invalid
{
&Resource{
Schema: map[string]*Schema{
"foo": &Schema{
Type: TypeList,
Elem: &Resource{
Schema: map[string]*Schema{
"foo": new(Schema),
},
},
},
},
},
true,
},
// Sub-resource valid
{
&Resource{
Schema: map[string]*Schema{
"foo": &Schema{
Type: TypeList,
Elem: &Resource{
Schema: map[string]*Schema{
"foo": &Schema{
Type: TypeInt,
},
},
},
},
},
},
false,
},
}
for i, tc := range cases {