From aa07f34dbe71f719da69f31f2faa85c8a407ce01 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 1 Jun 2018 09:57:29 -0400 Subject: [PATCH] core: TestContext2Apply_createBeforeDestroy_hook The instnace info ID has changed, and no longer reflects the type of node. Record the state to determine apply order for this test. --- terraform/context_apply_test.go | 9 +++++++-- terraform/state.go | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index fe5f404676..91961e6ec4 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -1008,8 +1008,9 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { var actualLock sync.Mutex h.PostApplyFn = func(n *InstanceInfo, s *InstanceState, e error) (HookAction, error) { actualLock.Lock() + defer actualLock.Unlock() - actual = append(actual, n.Id) + actual = append(actual, s.String()) return HookActionContinue, nil } @@ -1034,7 +1035,11 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { t.Fatalf("apply errors: %s", diags.Err()) } - expected := []string{"aws_instance.bar", "aws_instance.bar (deposed #0)"} + expected := []string{ + "ID = foo\nrequire_new = xyz\ntype = aws_instance\nTainted = false\n", + "", + } + if !reflect.DeepEqual(actual, expected) { t.Fatalf("bad: %#v", actual) } diff --git a/terraform/state.go b/terraform/state.go index 0d303b0fef..bdc2538d98 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -1770,13 +1770,19 @@ func (s *InstanceState) MergeDiff(d *InstanceDiff) *InstanceState { } func (s *InstanceState) String() string { + notCreated := "" + + if s == nil { + return notCreated + } + s.Lock() defer s.Unlock() var buf bytes.Buffer - if s == nil || s.ID == "" { - return "" + if s.ID == "" { + return notCreated } buf.WriteString(fmt.Sprintf("ID = %s\n", s.ID))