From ad6be99f5b717bd4cece59b9e668a03707470697 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Feb 2015 13:15:30 -0800 Subject: [PATCH 1/3] helper/schema: failing test --- helper/schema/schema_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index bb32374f3..a0fc18c2b 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -2009,6 +2009,29 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + + // #50 + { + Schema: map[string]*Schema{ + "active": &Schema{ + Type: TypeBool, + Computed: true, + ForceNew: true, + }, + }, + + State: &terraform.InstanceState{ + Attributes: map[string]string{ + "active": "true", + }, + }, + + Config: map[string]interface{}{}, + + Diff: nil, + + Err: false, + }, } for i, tc := range cases { From bcdec738d422de940cdee79fe94d3d407e7341e0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Feb 2015 13:16:59 -0800 Subject: [PATCH 2/3] helper/schema: default the new value to zero only for the decode --- helper/schema/schema.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index d8b4e8166..d781da282 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -810,13 +810,14 @@ func (m schemaMap) diffString( originalN = n n = schema.StateFunc(n) } - if n == nil { - n = schema.Type.Zero() + nraw := n + if nraw == nil { + nraw = schema.Type.Zero() } if err := mapstructure.WeakDecode(o, &os); err != nil { return fmt.Errorf("%s: %s", k, err) } - if err := mapstructure.WeakDecode(n, &ns); err != nil { + if err := mapstructure.WeakDecode(nraw, &ns); err != nil { return fmt.Errorf("%s: %s", k, err) } From fd274d7328ea517491d346be5425a48325af4347 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Feb 2015 13:17:23 -0800 Subject: [PATCH 3/3] helper/schema: update test desc --- helper/schema/schema_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index a0fc18c2b..8f6119490 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -2010,7 +2010,7 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, - // #50 + // #50 - A set computed element shouldn't cause a diff { Schema: map[string]*Schema{ "active": &Schema{