mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
88b5607a7a
Previously we fetched schemas during the AttachSchemaTransformer, potentially multiple times as that was re-run for each graph built. Now we fetch the schemas just once during context construction, passing that result into each of the graph builders. This only addresses the schema accesses during graph construction. We're still separately loading schemas during the main walk for evaluation purposes. This will be addressed in a later commit.
104 lines
2.7 KiB
Go
104 lines
2.7 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
func TestRefreshGraphBuilder_configOrphans(t *testing.T) {
|
|
|
|
m := testModule(t, "refresh-config-orphan")
|
|
|
|
state := &State{
|
|
Modules: []*ModuleState{
|
|
&ModuleState{
|
|
Path: rootModulePath,
|
|
Resources: map[string]*ResourceState{
|
|
"test_object.foo.0": &ResourceState{
|
|
Type: "test_object",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "foo",
|
|
},
|
|
},
|
|
},
|
|
"test_object.foo.1": &ResourceState{
|
|
Type: "test_object",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "bar",
|
|
},
|
|
},
|
|
},
|
|
"test_object.foo.2": &ResourceState{
|
|
Type: "test_object",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "baz",
|
|
},
|
|
},
|
|
},
|
|
"data.test_object.foo.0": &ResourceState{
|
|
Type: "test_object",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "foo",
|
|
},
|
|
},
|
|
},
|
|
"data.test_object.foo.1": &ResourceState{
|
|
Type: "test_object",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "bar",
|
|
},
|
|
},
|
|
},
|
|
"data.test_object.foo.2": &ResourceState{
|
|
Type: "test_object",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "baz",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
b := &RefreshGraphBuilder{
|
|
Config: m,
|
|
State: state,
|
|
Components: simpleMockComponentFactory(),
|
|
Schemas: simpleTestSchemas(),
|
|
}
|
|
g, err := b.Build(addrs.RootModuleInstance)
|
|
if err != nil {
|
|
t.Fatalf("Error building graph: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.StringWithNodeTypes())
|
|
expected := strings.TrimSpace(`
|
|
data.test_object.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
|
|
provider.test - *terraform.NodeApplyableProvider
|
|
data.test_object.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
|
|
provider.test - *terraform.NodeApplyableProvider
|
|
data.test_object.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
|
|
provider.test - *terraform.NodeApplyableProvider
|
|
provider.test - *terraform.NodeApplyableProvider
|
|
provider.test (close) - *terraform.graphNodeCloseProvider
|
|
data.test_object.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
|
|
data.test_object.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
|
|
data.test_object.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
|
|
test_object.foo - *terraform.NodeRefreshableManagedResource
|
|
test_object.foo - *terraform.NodeRefreshableManagedResource
|
|
provider.test - *terraform.NodeApplyableProvider
|
|
`)
|
|
if expected != actual {
|
|
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
|
|
}
|
|
}
|