2016-09-23 11:19:09 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-05-04 21:24:06 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2016-09-23 11:19:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestModuleVariableTransformer(t *testing.T) {
|
2018-05-04 21:24:06 -05:00
|
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
2016-09-23 11:19:09 -05:00
|
|
|
module := testModule(t, "transform-module-var-basic")
|
|
|
|
|
|
|
|
{
|
2018-05-04 21:24:06 -05:00
|
|
|
tf := &RootVariableTransformer{Config: module}
|
2016-09-23 11:19:09 -05:00
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-05-04 21:24:06 -05:00
|
|
|
tf := &ModuleVariableTransformer{Config: module}
|
2016-09-23 11:19:09 -05:00
|
|
|
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) {
|
2018-05-04 21:24:06 -05:00
|
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
2016-09-23 11:19:09 -05:00
|
|
|
module := testModule(t, "transform-module-var-nested")
|
|
|
|
|
|
|
|
{
|
2018-05-04 21:24:06 -05:00
|
|
|
tf := &RootVariableTransformer{Config: module}
|
2016-09-23 11:19:09 -05:00
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-05-04 21:24:06 -05:00
|
|
|
tf := &ModuleVariableTransformer{Config: module}
|
2016-09-23 11:19:09 -05:00
|
|
|
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 = `
|
2020-05-12 09:54:43 -05:00
|
|
|
module.child.var.value (expand)
|
2016-09-23 11:19:09 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
const testTransformModuleVarNestedStr = `
|
2020-05-12 09:54:43 -05:00
|
|
|
module.child.module.child.var.value (expand)
|
|
|
|
module.child.var.value (expand)
|
2016-09-23 11:19:09 -05:00
|
|
|
`
|