terraform: tests for ReferenceMap.References
This commit is contained in:
parent
b7954a42fe
commit
b488e51f56
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue