1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package ast
import (
"testing"
)
func TestVariableAccessType(t *testing.T) {
c := &VariableAccess{Name: "foo"}
scope := &BasicScope{
VarMap: map[string]Variable{
"foo": Variable{Type: TypeString},
},
}
actual, err := c.Type(scope)
if err != nil {
t.Fatalf("err: %s", err)
}
if actual != TypeString {
t.Fatalf("bad: %s", actual)
}
}
func TestVariableAccessType_invalid(t *testing.T) {
c := &VariableAccess{Name: "bar"}
scope := &BasicScope{
VarMap: map[string]Variable{
"foo": Variable{Type: TypeString},
},
}
_, err := c.Type(scope)
if err == nil {
t.Fatal("should error")
}
}
func TestVariableAccessType_list(t *testing.T) {
c := &VariableAccess{Name: "baz"}
scope := &BasicScope{
VarMap: map[string]Variable{
"baz": Variable{Type: TypeList},
},
}
actual, err := c.Type(scope)
if err != nil {
t.Fatalf("err: %s", err)
}
if actual != TypeList {
t.Fatalf("bad: %s", actual)
}
}
|