mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-19 17:59:05 -05:00
In order to generate OpenTelemetry traces of the main work that OpenTofu Core does we'll need to be able to propagate the active trace context into the main "Execute" method of each graph node, since that's where we typically make requests to providers, and other such work that could take a noticeable amount of time. Changing these frequently-used interfaces is always a noisy diff, so this commit intentionally focuses only on changing the signature of that interface and its one caller, and then dealing with all of the fallout of that on existing unit test code. For any use of Execute that was affected by this change we'll also switch to our newer naming scheme of using "evalCtx" as the name of the tofu.EvalContext variable, in preparation for using "ctx" idiomatically to refer to context.Context. However, the implementations currently don't yet name their context.Context argument because the method bodies don't yet make use of it. We'll name each of those arguments to "ctx" individually as we gradually add tracing support to each graph node type. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
55 lines
1.4 KiB
Go
55 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,
|
|
},
|
|
addrs.NoKey,
|
|
)
|
|
evalCtx := &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(t.Context(), evalCtx, 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")
|
|
}
|
|
}
|