mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 23:50:12 -06:00
cb2e9119aa
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package tofu
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/opentofu/opentofu/internal/addrs"
|
|
"github.com/opentofu/opentofu/internal/states"
|
|
)
|
|
|
|
func TestNodeDataDestroyExecute(t *testing.T) {
|
|
state := states.NewState()
|
|
state.Module(addrs.RootModuleInstance).SetResourceInstanceCurrent(
|
|
addrs.Resource{
|
|
Mode: addrs.DataResourceMode,
|
|
Type: "test_instance",
|
|
Name: "foo",
|
|
}.Instance(addrs.NoKey),
|
|
&states.ResourceInstanceObjectSrc{
|
|
Status: states.ObjectReady,
|
|
AttrsJSON: []byte(`{"dynamic":{"type":"string","value":"hello"}}`),
|
|
},
|
|
addrs.AbsProviderConfig{
|
|
Provider: addrs.NewDefaultProvider("test"),
|
|
Module: addrs.RootModule,
|
|
},
|
|
)
|
|
ctx := &MockEvalContext{
|
|
StateState: state.SyncWrapper(),
|
|
}
|
|
|
|
node := NodeDestroyableDataResourceInstance{&NodeAbstractResourceInstance{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.DataResourceMode,
|
|
Type: "test_instance",
|
|
Name: "foo",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
}}
|
|
|
|
diags := node.Execute(ctx, walkApply)
|
|
if diags.HasErrors() {
|
|
t.Fatalf("unexpected error: %v", diags.Err())
|
|
}
|
|
|
|
// verify resource removed from state
|
|
if state.HasManagedResourceInstanceObjects() {
|
|
t.Fatal("resources still in state after NodeDataDestroy.Execute")
|
|
}
|
|
}
|