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

     1  package ast
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestVariableAccessType(t *testing.T) {
     8  	c := &VariableAccess{Name: "foo"}
     9  	scope := &BasicScope{
    10  		VarMap: map[string]Variable{
    11  			"foo": Variable{Type: TypeString},
    12  		},
    13  	}
    14  
    15  	actual, err := c.Type(scope)
    16  	if err != nil {
    17  		t.Fatalf("err: %s", err)
    18  	}
    19  	if actual != TypeString {
    20  		t.Fatalf("bad: %s", actual)
    21  	}
    22  }
    23  
    24  func TestVariableAccessType_invalid(t *testing.T) {
    25  	c := &VariableAccess{Name: "bar"}
    26  	scope := &BasicScope{
    27  		VarMap: map[string]Variable{
    28  			"foo": Variable{Type: TypeString},
    29  		},
    30  	}
    31  
    32  	_, err := c.Type(scope)
    33  	if err == nil {
    34  		t.Fatal("should error")
    35  	}
    36  }