terraform: tests for ReferenceMap.References

This commit is contained in:
Mitchell Hashimoto 2016-11-04 18:40:09 -07:00
parent b7954a42fe
commit b488e51f56
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 47 additions and 0 deletions

View File

@ -1,8 +1,12 @@
package terraform
import (
"reflect"
"sort"
"strings"
"testing"
"github.com/hashicorp/terraform/dag"
)
func TestReferenceTransformer_simple(t *testing.T) {
@ -84,6 +88,49 @@ func TestReferenceTransformer_path(t *testing.T) {
}
}
func TestReferenceMapReferences(t *testing.T) {
cases := map[string]struct {
Nodes []dag.Vertex
Check dag.Vertex
Result []string
}{
"simple": {
Nodes: []dag.Vertex{
&graphNodeRefParentTest{
NameValue: "A",
Names: []string{"A"},
},
},
Check: &graphNodeRefChildTest{
NameValue: "foo",
Refs: []string{"A"},
},
Result: []string{"A"},
},
}
for tn, tc := range cases {
t.Run(tn, func(t *testing.T) {
rm := NewReferenceMap(tc.Nodes)
result, err := rm.References(tc.Check)
if err != nil {
t.Fatalf("err: %s", err)
}
var resultStr []string
for _, v := range result {
resultStr = append(resultStr, dag.VertexName(v))
}
sort.Strings(resultStr)
sort.Strings(tc.Result)
if !reflect.DeepEqual(resultStr, tc.Result) {
t.Fatalf("bad: %#v", resultStr)
}
})
}
}
type graphNodeRefParentTest struct {
NameValue string
PathValue []string