github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/terraform/transform_module_variable_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestModuleVariableTransformer(t *testing.T) {
     9  	g := Graph{Path: RootModulePath}
    10  	module := testModule(t, "transform-module-var-basic")
    11  
    12  	{
    13  		tf := &RootVariableTransformer{Module: module}
    14  		if err := tf.Transform(&g); err != nil {
    15  			t.Fatalf("err: %s", err)
    16  		}
    17  	}
    18  
    19  	{
    20  		tf := &ModuleVariableTransformer{Module: module, DisablePrune: true}
    21  		if err := tf.Transform(&g); err != nil {
    22  			t.Fatalf("err: %s", err)
    23  		}
    24  	}
    25  
    26  	actual := strings.TrimSpace(g.String())
    27  	expected := strings.TrimSpace(testTransformModuleVarBasicStr)
    28  	if actual != expected {
    29  		t.Fatalf("bad:\n\n%s", actual)
    30  	}
    31  }
    32  
    33  func TestModuleVariableTransformer_nested(t *testing.T) {
    34  	g := Graph{Path: RootModulePath}
    35  	module := testModule(t, "transform-module-var-nested")
    36  
    37  	{
    38  		tf := &RootVariableTransformer{Module: module}
    39  		if err := tf.Transform(&g); err != nil {
    40  			t.Fatalf("err: %s", err)
    41  		}
    42  	}
    43  
    44  	{
    45  		tf := &ModuleVariableTransformer{Module: module, DisablePrune: true}
    46  		if err := tf.Transform(&g); err != nil {
    47  			t.Fatalf("err: %s", err)
    48  		}
    49  	}
    50  
    51  	actual := strings.TrimSpace(g.String())
    52  	expected := strings.TrimSpace(testTransformModuleVarNestedStr)
    53  	if actual != expected {
    54  		t.Fatalf("bad:\n\n%s", actual)
    55  	}
    56  }
    57  
    58  const testTransformModuleVarBasicStr = `
    59  module.child.var.value
    60  `
    61  
    62  const testTransformModuleVarNestedStr = `
    63  module.child.module.child.var.value
    64  module.child.var.value
    65  `