helper/schema: improve InternalValidate for sets
This commit is contained in:
parent
9ab5577beb
commit
e9cc09a886
|
@ -178,14 +178,15 @@ func (m schemaMap) InternalValidate() error {
|
|||
return fmt.Errorf("%s: ComputedWhen can only be set with Computed", k)
|
||||
}
|
||||
|
||||
if v.Type == TypeList {
|
||||
if v.Type == TypeList || v.Type == TypeSet {
|
||||
if v.Elem == nil {
|
||||
return fmt.Errorf("%s: Elem must be set for lists", k)
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
if v.Set != nil {
|
||||
if v.Type == TypeList && v.Set != nil {
|
||||
return fmt.Errorf("%s: Set can only be set for TypeSet", k)
|
||||
} else if v.Type == TypeSet && v.Set == nil {
|
||||
return fmt.Errorf("%s: Set must be set", k)
|
||||
}
|
||||
|
||||
switch t := v.Elem.(type) {
|
||||
|
|
|
@ -784,6 +784,29 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
true,
|
||||
},
|
||||
|
||||
// List element with Set set
|
||||
{
|
||||
map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeList,
|
||||
Elem: &Schema{Type: TypeInt},
|
||||
Set: func(interface{}) int { return 0 },
|
||||
},
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
// Set element with no Set set
|
||||
{
|
||||
map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeSet,
|
||||
Elem: &Schema{Type: TypeInt},
|
||||
},
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
// Required but computed
|
||||
{
|
||||
map[string]*Schema{
|
||||
|
|
Loading…
Reference in New Issue