github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/config/lang/transform_fixed_test.go (about)

     1  package lang
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/config/lang/ast"
     8  )
     9  
    10  func TestFixedValueTransform(t *testing.T) {
    11  	cases := []struct {
    12  		Input  ast.Node
    13  		Output ast.Node
    14  	}{
    15  		{
    16  			&ast.LiteralNode{Value: 42},
    17  			&ast.LiteralNode{Value: 42},
    18  		},
    19  
    20  		{
    21  			&ast.VariableAccess{Name: "bar"},
    22  			&ast.LiteralNode{Value: "foo"},
    23  		},
    24  
    25  		{
    26  			&ast.Concat{
    27  				Exprs: []ast.Node{
    28  					&ast.VariableAccess{Name: "bar"},
    29  					&ast.LiteralNode{Value: 42},
    30  				},
    31  			},
    32  			&ast.Concat{
    33  				Exprs: []ast.Node{
    34  					&ast.LiteralNode{Value: "foo"},
    35  					&ast.LiteralNode{Value: 42},
    36  				},
    37  			},
    38  		},
    39  	}
    40  
    41  	value := &ast.LiteralNode{Value: "foo"}
    42  	for _, tc := range cases {
    43  		actual := FixedValueTransform(tc.Input, value)
    44  		if !reflect.DeepEqual(actual, tc.Output) {
    45  			t.Fatalf("bad: %#v\n\nInput: %#v", actual, tc.Input)
    46  		}
    47  	}
    48  }