helper/schema: more tests
This commit is contained in:
parent
d05b9d6193
commit
660dc68a86
|
@ -143,6 +143,11 @@ func (m schemaMap) diffList(
|
|||
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
|
||||
countSchema := &Schema{
|
||||
Type: TypeInt,
|
||||
|
|
|
@ -355,6 +355,87 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue