mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
bedc08f5eb
* terraform: refactor EvalWriteStateDeposed EvalWriteStateDeposed is now NodeDestroyDeposedResourceInstanceObject.writeResourceInstanceState. Since that's the only caller I considered putting the logic directly inline, but things are clunky enough right now that I think this is good enough for this refactor.
34 lines
860 B
Go
34 lines
860 B
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/states"
|
|
)
|
|
|
|
func TestUpdateStateHook(t *testing.T) {
|
|
mockHook := new(MockHook)
|
|
|
|
state := states.NewState()
|
|
state.Module(addrs.RootModuleInstance).SetLocalValue("foo", cty.StringVal("hello"))
|
|
|
|
ctx := new(MockEvalContext)
|
|
ctx.HookHook = mockHook
|
|
ctx.StateState = state.SyncWrapper()
|
|
|
|
if err := UpdateStateHook(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !mockHook.PostStateUpdateCalled {
|
|
t.Fatal("should call PostStateUpdate")
|
|
}
|
|
if mockHook.PostStateUpdateState.LocalValue(addrs.LocalValue{Name: "foo"}.Absolute(addrs.RootModuleInstance)) != cty.StringVal("hello") {
|
|
t.Fatalf("wrong state passed to hook: %s", spew.Sdump(mockHook.PostStateUpdateState))
|
|
}
|
|
}
|