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:
parent
f1657bb3e3
commit
058df3563f
|
@ -15,6 +15,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/go-test/deep"
|
"github.com/go-test/deep"
|
||||||
"github.com/zclconf/go-cty/cty"
|
"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
|
var actualLock sync.Mutex
|
||||||
h.PostApplyFn = func(addr addrs.AbsResourceInstance, gen states.Generation, sv cty.Value, e error) (HookAction, error) {
|
h.PostApplyFn = func(addr addrs.AbsResourceInstance, gen states.Generation, sv cty.Value, e error) (HookAction, error) {
|
||||||
actualLock.Lock()
|
actualLock.Lock()
|
||||||
|
|
||||||
defer actualLock.Unlock()
|
defer actualLock.Unlock()
|
||||||
actual = append(actual, state.String())
|
actual = append(actual, sv)
|
||||||
return HookActionContinue, nil
|
return HookActionContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,13 +1049,18 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) {
|
||||||
t.Fatalf("apply errors: %s", diags.Err())
|
t.Fatalf("apply errors: %s", diags.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := []string{
|
expected := []cty.Value{
|
||||||
"ID = foo\nrequire_new = xyz\ntype = aws_instance\nTainted = false\n",
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
"<not created>",
|
"id": cty.StringVal("foo"),
|
||||||
|
"require_new": cty.StringVal("xyz"),
|
||||||
|
"type": cty.StringVal("aws_instance"),
|
||||||
|
}),
|
||||||
|
cty.NullVal(cty.DynamicPseudoType),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
cmpOpt := cmp.Transformer("ctyshim", hcl2shim.ConfigValueFromHCL2)
|
||||||
t.Fatalf("bad: %#v", actual)
|
if !cmp.Equal(actual, expected, cmpOpt) {
|
||||||
|
t.Fatalf("wrong state snapshot sequence\n%s", cmp.Diff(expected, actual, cmpOpt))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue