From 4099c6483300856ff17356ce255e57c63e8be2e5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 21 Jul 2014 11:36:21 -0700 Subject: [PATCH] config: tests, so many tests --- config/interpolate_test.go | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/config/interpolate_test.go b/config/interpolate_test.go index 5f77f64b7..3e399bf65 100644 --- a/config/interpolate_test.go +++ b/config/interpolate_test.go @@ -5,6 +5,69 @@ import ( "testing" ) +func TestNewInterpolation(t *testing.T) { + cases := []struct { + Input string + Result Interpolation + Error bool + }{ + { + "foo", + nil, + true, + }, + + { + "var.foo", + &VariableInterpolation{ + Variable: &UserVariable{ + Name: "foo", + key: "var.foo", + }, + key: "var.foo", + }, + false, + }, + } + + for i, tc := range cases { + actual, err := NewInterpolation(tc.Input) + if (err != nil) != tc.Error { + t.Fatalf("%d. Error: %s", i, err) + } + if !reflect.DeepEqual(actual, tc.Result) { + t.Fatalf("%d bad: %#v", i, actual) + } + } +} + +func TestNewInterpolatedVariable(t *testing.T) { + cases := []struct { + Input string + Result InterpolatedVariable + Error bool + }{ + { + "var.foo", + &UserVariable{ + Name: "foo", + key: "var.foo", + }, + false, + }, + } + + for i, tc := range cases { + actual, err := NewInterpolatedVariable(tc.Input) + if (err != nil) != tc.Error { + t.Fatalf("%d. Error: %s", i, err) + } + if !reflect.DeepEqual(actual, tc.Result) { + t.Fatalf("%d bad: %#v", i, actual) + } + } +} + func TestNewResourceVariable(t *testing.T) { v, err := NewResourceVariable("foo.bar.baz") if err != nil {