terraform: test for Resource.Vars
This commit is contained in:
parent
ff79fa9c9f
commit
361dbb14ae
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue