helper/schema: more tests

This commit is contained in:
Mitchell Hashimoto 2014-08-15 10:39:40 -07:00
parent d05b9d6193
commit 660dc68a86
2 changed files with 86 additions and 0 deletions

View File

@ -143,6 +143,11 @@ func (m schemaMap) diffList(
return fmt.Errorf("%s: must be a list", k) return fmt.Errorf("%s: must be a list", k)
} }
// If this field is required, then it must also be non-empty
if len(vs) == 0 && schema.Required {
return fmt.Errorf("%s: required field is not set", k)
}
// Diff the count no matter what // Diff the count no matter what
countSchema := &Schema{ countSchema := &Schema{
Type: TypeInt, Type: TypeInt,

View File

@ -355,6 +355,87 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false, Err: false,
}, },
{
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Required: true,
Elem: &Resource{
Schema: map[string]*Schema{
"from": &Schema{
Type: TypeInt,
Required: true,
},
},
},
},
},
State: nil,
Config: map[string]interface{}{},
Diff: nil,
Err: true,
},
{
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Required: true,
Elem: &Resource{
Schema: map[string]*Schema{
"from": &Schema{
Type: TypeInt,
Required: true,
},
},
},
},
},
State: nil,
Config: map[string]interface{}{
"ingress": []interface{}{},
},
Diff: nil,
Err: true,
},
{
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Required: true,
Elem: &Resource{
Schema: map[string]*Schema{
"from": &Schema{
Type: TypeInt,
Required: true,
},
},
},
},
},
State: nil,
Config: map[string]interface{}{
"ingress": []interface{}{
map[string]interface{}{},
},
},
Diff: nil,
Err: true,
},
} }
for i, tc := range cases { for i, tc := range cases {