config: tests, so many tests

This commit is contained in:
Mitchell Hashimoto 2014-07-21 11:36:21 -07:00
parent e8fe26488a
commit 4099c64833
1 changed files with 63 additions and 0 deletions

View File

@ -5,6 +5,69 @@ import (
"testing" "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) { func TestNewResourceVariable(t *testing.T) {
v, err := NewResourceVariable("foo.bar.baz") v, err := NewResourceVariable("foo.bar.baz")
if err != nil { if err != nil {