helper/schema: Bools and ints can decode

This commit is contained in:
Mitchell Hashimoto 2014-08-14 20:02:52 -07:00
parent efa2335886
commit 46d911325a
2 changed files with 77 additions and 1 deletions

View File

@ -12,7 +12,7 @@ type ValueType int
const (
TypeInvalid ValueType = iota
TypeBoolean
TypeBool
TypeInt
TypeString
TypeList
@ -67,8 +67,14 @@ func (m schemaMap) Diff(
var err error
switch schema.Type {
case TypeBool:
fallthrough
case TypeInt:
fallthrough
case TypeString:
attrD, err = m.diffString(k, schema, s, c)
default:
err = fmt.Errorf("%s: unknown type %s", k, schema.Type)
}
if err != nil {

View File

@ -16,6 +16,10 @@ func TestSchemaMap_Diff(t *testing.T) {
Diff *terraform.ResourceDiff
Err bool
}{
/*
* String decode
*/
{
Schema: map[string]*Schema{
"availability_zone": &Schema{
@ -88,6 +92,72 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: true,
},
/*
* Int decode
*/
{
Schema: map[string]*Schema{
"port": &Schema{
Type: TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},
},
State: nil,
Config: map[string]interface{}{
"port": 27,
},
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"port": &terraform.ResourceAttrDiff{
Old: "",
New: "27",
RequiresNew: true,
},
},
},
Err: false,
},
/*
* Bool decode
*/
{
Schema: map[string]*Schema{
"port": &Schema{
Type: TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
},
State: nil,
Config: map[string]interface{}{
"port": false,
},
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"port": &terraform.ResourceAttrDiff{
Old: "",
New: "0",
RequiresNew: true,
},
},
},
Err: false,
},
}
for i, tc := range cases {