github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/node_module_variable_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/config"
     8  )
     9  
    10  func TestNodeApplyableModuleVariablePath(t *testing.T) {
    11  	n := &NodeApplyableModuleVariable{
    12  		PathValue: []string{"root", "child"},
    13  		Config:    &config.Variable{Name: "foo"},
    14  	}
    15  
    16  	expected := []string{"root"}
    17  	actual := n.Path()
    18  	if !reflect.DeepEqual(actual, expected) {
    19  		t.Fatalf("%#v != %#v", actual, expected)
    20  	}
    21  }
    22  
    23  func TestNodeApplyableModuleVariableReferenceableName(t *testing.T) {
    24  	n := &NodeApplyableModuleVariable{
    25  		PathValue: []string{"root", "child"},
    26  		Config:    &config.Variable{Name: "foo"},
    27  	}
    28  
    29  	expected := []string{"module.child.var.foo"}
    30  	actual := n.ReferenceableName()
    31  	if !reflect.DeepEqual(actual, expected) {
    32  		t.Fatalf("%#v != %#v", actual, expected)
    33  	}
    34  }
    35  
    36  func TestNodeApplyableModuleVariableReference(t *testing.T) {
    37  	n := &NodeApplyableModuleVariable{
    38  		PathValue: []string{"root", "child"},
    39  		Config:    &config.Variable{Name: "foo"},
    40  		Value: config.TestRawConfig(t, map[string]interface{}{
    41  			"foo": `${var.foo}`,
    42  		}),
    43  	}
    44  
    45  	expected := []string{"var.foo"}
    46  	actual := n.References()
    47  	if !reflect.DeepEqual(actual, expected) {
    48  		t.Fatalf("%#v != %#v", actual, expected)
    49  	}
    50  }
    51  
    52  func TestNodeApplyableModuleVariableReference_grandchild(t *testing.T) {
    53  	n := &NodeApplyableModuleVariable{
    54  		PathValue: []string{"root", "child", "grandchild"},
    55  		Config:    &config.Variable{Name: "foo"},
    56  		Value: config.TestRawConfig(t, map[string]interface{}{
    57  			"foo": `${var.foo}`,
    58  		}),
    59  	}
    60  
    61  	expected := []string{"module.child.var.foo"}
    62  	actual := n.References()
    63  	if !reflect.DeepEqual(actual, expected) {
    64  		t.Fatalf("%#v != %#v", actual, expected)
    65  	}
    66  }