mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 17:31:30 -06:00
38ec730b0e
Previously the graph builders all expected to be given a full manifest of all of the plugin component schemas that they could need during their analysis work. That made sense when terraform.NewContext would always proactively load all of the schemas before doing any other work, but we now have a load-as-needed strategy for schemas. We'll now have the graph builders use the contextPlugins object they each already hold to retrieve individual schemas when needed. This avoids the need to prepare a redundant data structure to pass alongside the contextPlugins object, and leans on the memoization behavior inside contextPlugins to preserve the old behavior of loading each provider's schema only once.
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func TestTransitiveReductionTransformer(t *testing.T) {
|
|
mod := testModule(t, "transform-trans-reduce-basic")
|
|
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
|
{
|
|
tf := &ConfigTransformer{Config: mod}
|
|
if err := tf.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
t.Logf("graph after ConfigTransformer:\n%s", g.String())
|
|
}
|
|
|
|
{
|
|
transform := &AttachResourceConfigTransformer{Config: mod}
|
|
if err := transform.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
{
|
|
transform := &AttachSchemaTransformer{
|
|
Plugins: schemaOnlyProvidersForTesting(map[addrs.Provider]*ProviderSchema{
|
|
addrs.NewDefaultProvider("aws"): {
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
"aws_instance": {
|
|
Attributes: map[string]*configschema.Attribute{
|
|
"A": {
|
|
Type: cty.String,
|
|
Optional: true,
|
|
},
|
|
"B": {
|
|
Type: cty.String,
|
|
Optional: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
}
|
|
if err := transform.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
{
|
|
transform := &ReferenceTransformer{}
|
|
if err := transform.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
t.Logf("graph after ReferenceTransformer:\n%s", g.String())
|
|
}
|
|
|
|
{
|
|
transform := &TransitiveReductionTransformer{}
|
|
if err := transform.Transform(&g); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
t.Logf("graph after TransitiveReductionTransformer:\n%s", g.String())
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(testTransformTransReduceBasicStr)
|
|
if actual != expected {
|
|
t.Errorf("wrong result\ngot:\n%s\n\nwant:\n%s", actual, expected)
|
|
}
|
|
}
|
|
|
|
const testTransformTransReduceBasicStr = `
|
|
aws_instance.A
|
|
aws_instance.B
|
|
aws_instance.A
|
|
aws_instance.C
|
|
aws_instance.B
|
|
`
|