From 058df3563f1f9153da864aa6736f6007784dfc49 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 24 Sep 2018 13:52:08 -0700 Subject: [PATCH] core: fix TestContext2Apply_createBeforeDestroy_hook This test was incorrectly updated to the new hook API; it should've been recording the individual resource state values passed to the hook, not the original state as a whole (which is not yet updated at the point when the hook is called). --- terraform/context_apply_test.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 02599619c..c9bd669e9 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -15,6 +15,7 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "github.com/google/go-cmp/cmp" "github.com/go-test/deep" "github.com/zclconf/go-cty/cty" @@ -1017,13 +1018,13 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { }, }) - var actual []string + var actual []cty.Value var actualLock sync.Mutex h.PostApplyFn = func(addr addrs.AbsResourceInstance, gen states.Generation, sv cty.Value, e error) (HookAction, error) { actualLock.Lock() defer actualLock.Unlock() - actual = append(actual, state.String()) + actual = append(actual, sv) return HookActionContinue, nil } @@ -1048,13 +1049,18 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { t.Fatalf("apply errors: %s", diags.Err()) } - expected := []string{ - "ID = foo\nrequire_new = xyz\ntype = aws_instance\nTainted = false\n", - "", + expected := []cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + "id": cty.StringVal("foo"), + "require_new": cty.StringVal("xyz"), + "type": cty.StringVal("aws_instance"), + }), + cty.NullVal(cty.DynamicPseudoType), } - if !reflect.DeepEqual(actual, expected) { - t.Fatalf("bad: %#v", actual) + cmpOpt := cmp.Transformer("ctyshim", hcl2shim.ConfigValueFromHCL2) + if !cmp.Equal(actual, expected, cmpOpt) { + t.Fatalf("wrong state snapshot sequence\n%s", cmp.Diff(expected, actual, cmpOpt)) } }