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.
This commit is contained in:
James Bardin 2018-06-01 09:57:29 -04:00 committed by Martin Atkins
parent 403abb52b9
commit aa07f34dbe
2 changed files with 15 additions and 4 deletions

View File

@ -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",
"<not created>",
}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}

View File

@ -1770,13 +1770,19 @@ func (s *InstanceState) MergeDiff(d *InstanceDiff) *InstanceState {
}
func (s *InstanceState) String() string {
notCreated := "<not created>"
if s == nil {
return notCreated
}
s.Lock()
defer s.Unlock()
var buf bytes.Buffer
if s == nil || s.ID == "" {
return "<not created>"
if s.ID == "" {
return notCreated
}
buf.WriteString(fmt.Sprintf("ID = %s\n", s.ID))