mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: tests for ReferenceMap.References
This commit is contained in:
parent
b7954a42fe
commit
b488e51f56
@ -1,8 +1,12 @@
|
|||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/dag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReferenceTransformer_simple(t *testing.T) {
|
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 {
|
type graphNodeRefParentTest struct {
|
||||||
NameValue string
|
NameValue string
|
||||||
PathValue []string
|
PathValue []string
|
||||||
|
Loading…
Reference in New Issue
Block a user