mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
a3403f2766
Due to how often the state and plan types are referenced throughout Terraform, there isn't a great way to switch them out gradually. As a consequence, this huge commit gets us from the old world to a _compilable_ new world, but still has a large number of known test failures due to key functionality being stubbed out. The stubs here are for anything that interacts with providers, since we now need to do the follow-up work to similarly replace the old terraform.ResourceProvider interface with its replacement in the new "providers" package. That work, along with work to fix the remaining failing tests, will follow in subsequent commits. The aim here was to replace all references to terraform.State and its downstream types with states.State, terraform.Plan with plans.Plan, state.State with statemgr.State, and switch to the new implementations of the state and plan file formats. However, due to the number of times those types are used, this also ended up affecting numerous other parts of core such as terraform.Hook, the backend.Backend interface, and most of the CLI commands. Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize in advance to the person who inevitably just found this huge commit while spelunking through the commit history.
102 lines
3.9 KiB
Go
102 lines
3.9 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/plans"
|
|
"github.com/hashicorp/terraform/states"
|
|
)
|
|
|
|
func TestNilHook_impl(t *testing.T) {
|
|
var _ Hook = new(NilHook)
|
|
}
|
|
|
|
// testHook is a Hook implementation that logs the calls it receives.
|
|
// It is intended for testing that core code is emitting the correct hooks
|
|
// for a given situation.
|
|
type testHook struct {
|
|
Calls []*testHookCall
|
|
}
|
|
|
|
var _ Hook = (*testHook)(nil)
|
|
|
|
// testHookCall represents a single call in testHook.
|
|
// This hook just logs string names to make it easy to write "want" expressions
|
|
// in tests that can DeepEqual against the real calls.
|
|
type testHookCall struct {
|
|
Action string
|
|
InstanceID string
|
|
}
|
|
|
|
func (h *testHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PreApply", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, err error) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostApply", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PreDiff(addr addrs.AbsResourceInstance, gen states.Generation, priorState, proposedNewState cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PreDiff", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostDiff", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PreProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PreProvisionInstance", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostProvisionInstance", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PreProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PreProvisionInstanceStep", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string, err error) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostProvisionInstanceStep", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) ProvisionOutput(addr addrs.AbsResourceInstance, typeName string, line string) {
|
|
h.Calls = append(h.Calls, &testHookCall{"ProvisionOutput", addr.String()})
|
|
}
|
|
|
|
func (h *testHook) PreRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PreRefresh", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value, newState cty.Value) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostRefresh", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PreImportState(addr addrs.AbsResourceInstance, importID string) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PreImportState", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostImportState(addr addrs.AbsResourceInstance, imported []*states.ImportedObject) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostImportState", addr.String()})
|
|
return HookActionContinue, nil
|
|
}
|
|
|
|
func (h *testHook) PostStateUpdate(new *states.State) (HookAction, error) {
|
|
h.Calls = append(h.Calls, &testHookCall{"PostStateUpdate", ""})
|
|
return HookActionContinue, nil
|
|
}
|