opentofu/terraform/transform_module_variable_test.go
James Bardin 07c35dd4df update test strings
Match the new names output by the expander nodes
2020-05-12 11:07:00 -04:00

68 lines
1.4 KiB
Go

package terraform
import (
"strings"
"testing"
"github.com/hashicorp/terraform/addrs"
)
func TestModuleVariableTransformer(t *testing.T) {
g := Graph{Path: addrs.RootModuleInstance}
module := testModule(t, "transform-module-var-basic")
{
tf := &RootVariableTransformer{Config: module}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
tf := &ModuleVariableTransformer{Config: module}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformModuleVarBasicStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestModuleVariableTransformer_nested(t *testing.T) {
g := Graph{Path: addrs.RootModuleInstance}
module := testModule(t, "transform-module-var-nested")
{
tf := &RootVariableTransformer{Config: module}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
{
tf := &ModuleVariableTransformer{Config: module}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformModuleVarNestedStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
const testTransformModuleVarBasicStr = `
module.child.var.value (expand)
`
const testTransformModuleVarNestedStr = `
module.child.module.child.var.value (expand)
module.child.var.value (expand)
`