github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/durgaform/transform_module_variable_test.go (about)

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