From 361dbb14ae52c3e426994e63aeab06157021bda3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Jun 2014 20:59:23 -0700 Subject: [PATCH] terraform: test for Resource.Vars --- terraform/resource.go | 3 ++- terraform/resource_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 terraform/resource_test.go diff --git a/terraform/resource.go b/terraform/resource.go index a9db7e6a4..202116d63 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -15,7 +15,8 @@ type Resource struct { State *ResourceState } -// TODO: test +// Vars returns the mapping of variables that should be replaced in +// configuration based on the attributes of this resource. func (r *Resource) Vars() map[string]string { if r.State == nil { return nil diff --git a/terraform/resource_test.go b/terraform/resource_test.go new file mode 100644 index 000000000..9837cee29 --- /dev/null +++ b/terraform/resource_test.go @@ -0,0 +1,31 @@ +package terraform + +import ( + "reflect" + "testing" +) + +func TestResource_Vars(t *testing.T) { + r := new(Resource) + + if len(r.Vars()) > 0 { + t.Fatalf("bad: %#v", r.Vars()) + } + + r = &Resource{ + Id: "key", + State: &ResourceState{ + Attributes: map[string]string{ + "foo": "bar", + }, + }, + } + + expected := map[string]string{ + "key.foo": "bar", + } + actual := r.Vars() + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } +}