mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-16 03:32:54 -06:00
72e81de0fc
Some tests could not handle reading orphaned resources. It also turns out the ReadResource mock never returned the correct state in the default case at all.
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/configs/configschema"
|
|
"github.com/hashicorp/terraform/instances"
|
|
"github.com/hashicorp/terraform/plans"
|
|
"github.com/hashicorp/terraform/states"
|
|
)
|
|
|
|
func TestNodeResourcePlanOrphanExecute(t *testing.T) {
|
|
state := states.NewState()
|
|
state.Module(addrs.RootModuleInstance).SetResourceInstanceCurrent(
|
|
addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_object",
|
|
Name: "foo",
|
|
}.Instance(addrs.NoKey),
|
|
&states.ResourceInstanceObjectSrc{
|
|
AttrsFlat: map[string]string{
|
|
"test_string": "foo",
|
|
},
|
|
Status: states.ObjectReady,
|
|
},
|
|
addrs.AbsProviderConfig{
|
|
Provider: addrs.NewDefaultProvider("test"),
|
|
Module: addrs.RootModule,
|
|
},
|
|
)
|
|
|
|
p := simpleMockProvider()
|
|
ctx := &MockEvalContext{
|
|
StateState: state.SyncWrapper(),
|
|
RefreshStateState: state.SyncWrapper(),
|
|
InstanceExpanderExpander: instances.NewExpander(),
|
|
ProviderProvider: p,
|
|
ProviderSchemaSchema: &ProviderSchema{
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
"test_object": simpleTestSchema(),
|
|
},
|
|
},
|
|
ChangesChanges: plans.NewChanges().SyncWrapper(),
|
|
}
|
|
|
|
node := NodePlannableResourceInstanceOrphan{
|
|
NodeAbstractResourceInstance: &NodeAbstractResourceInstance{
|
|
NodeAbstractResource: NodeAbstractResource{
|
|
ResolvedProvider: addrs.AbsProviderConfig{
|
|
Provider: addrs.NewDefaultProvider("test"),
|
|
Module: addrs.RootModule,
|
|
},
|
|
},
|
|
Addr: mustResourceInstanceAddr("test_object.foo"),
|
|
},
|
|
}
|
|
err := node.Execute(ctx, walkApply)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %s", err.Error())
|
|
}
|
|
if !state.Empty() {
|
|
t.Fatalf("expected empty state, got %s", state.String())
|
|
}
|
|
}
|