From bb0980f5ba155bba2c245b9fa4092d141095a7b9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 24 May 2014 11:41:19 -0700 Subject: [PATCH] config: tests for instantiating interpolated var types --- config/config.go | 5 +++-- config/config_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 2ffbd1f67..953176bf2 100644 --- a/config/config.go +++ b/config/config.go @@ -52,7 +52,8 @@ type ResourceVariable struct { // that is inputted from outside the configuration. This looks like // "${var.foo}" type UserVariable struct { - name string + Name string + key string } @@ -74,7 +75,7 @@ func NewUserVariable(key string) (*UserVariable, error) { name := key[len("var."):] return &UserVariable{ key: key, - name: name, + Name: name, }, nil } diff --git a/config/config_test.go b/config/config_test.go index 756175cc2..e0bef17ca 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,4 +1,43 @@ package config +import ( + "testing" +) + // This is the directory where our test fixtures are. const fixtureDir = "./test-fixtures" + +func TestNewResourceVariable(t *testing.T) { + v, err := NewResourceVariable("foo.bar.baz") + if err != nil { + t.Fatalf("err: %s", err) + } + + if v.Type != "foo" { + t.Fatalf("bad: %#v", v) + } + if v.Name != "bar" { + t.Fatalf("bad: %#v", v) + } + if v.Field != "baz" { + t.Fatalf("bad: %#v", v) + } + + if v.FullKey() != "foo.bar.baz" { + t.Fatalf("bad: %#v", v) + } +} + +func TestNewUserVariable(t *testing.T) { + v, err := NewUserVariable("var.bar") + if err != nil { + t.Fatalf("err: %s", err) + } + + if v.Name != "bar" { + t.Fatalf("bad: %#v", v.Name) + } + if v.FullKey() != "var.bar" { + t.Fatalf("bad: %#v", v) + } +}