terraform: test for Resource.Vars

This commit is contained in:
Mitchell Hashimoto 2014-06-30 20:59:23 -07:00
parent ff79fa9c9f
commit 361dbb14ae
2 changed files with 33 additions and 1 deletions

View File

@ -15,7 +15,8 @@ type Resource struct {
State *ResourceState 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 { func (r *Resource) Vars() map[string]string {
if r.State == nil { if r.State == nil {
return nil return nil

View File

@ -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)
}
}