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).
This commit is contained in:
Martin Atkins 2018-09-24 13:52:08 -07:00
parent f1657bb3e3
commit 058df3563f
1 changed files with 13 additions and 7 deletions

View File

@ -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",
"<not created>",
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))
}
}