mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
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
|
||||
|
31
terraform/resource_test.go
Normal file
31
terraform/resource_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user