Skip to content

Commit

Permalink
helper/schema: validate Set is a set type [GH-413]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 18, 2014
1 parent 1912e96 commit 2b50d44
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BUG FIXES:
computed so the value is still unknown.
* core: If a resource fails to create and has provisioners, it is
marked as tainted. [GH-434]
* core: Set types are validated to be sets. [GH-413]
* providers/aws: Refresh of launch configs and autoscale groups load
the correct data and don't incorrectly recreate themselves. [GH-425]
* providers/aws: Fix case where ELB would incorrectly plan to modify
Expand Down
2 changes: 2 additions & 0 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ func (m schemaMap) validatePrimitive(
}

switch schema.Type {
case TypeSet:
fallthrough
case TypeList:
return m.validateList(k, raw, schema, c)
case TypeInt:
Expand Down
20 changes: 20 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,26 @@ func TestSchemaMap_Validate(t *testing.T) {

Err: true,
},

// Not a set
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeSet,
Required: true,
Elem: &Schema{Type: TypeInt},
Set: func(a interface{}) int {
return a.(int)
},
},
},

Config: map[string]interface{}{
"ports": "foo",
},

Err: true,
},
}

for i, tc := range cases {
Expand Down

0 comments on commit 2b50d44

Please sign in to comment.