terraform: reference transformer shouldn't make loop to self
This commit is contained in:
parent
5018617049
commit
38b9f7794d
|
@ -88,6 +88,18 @@ func (m *ReferenceMap) References(v dag.Vertex) ([]dag.Vertex, []string) {
|
|||
continue
|
||||
}
|
||||
|
||||
// Make sure this isn't a self reference, which isn't included
|
||||
selfRef := false
|
||||
for _, p := range parents {
|
||||
if p == v {
|
||||
selfRef = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if selfRef {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, parents...)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,29 @@ func TestReferenceTransformer_simple(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestReferenceTransformer_self(t *testing.T) {
|
||||
g := Graph{Path: RootModulePath}
|
||||
g.Add(&graphNodeRefParentTest{
|
||||
NameValue: "A",
|
||||
Names: []string{"A"},
|
||||
})
|
||||
g.Add(&graphNodeRefChildTest{
|
||||
NameValue: "B",
|
||||
Refs: []string{"A", "B"},
|
||||
})
|
||||
|
||||
tf := &ReferenceTransformer{}
|
||||
if err := tf.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTransformRefBasicStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReferenceTransformer_path(t *testing.T) {
|
||||
g := Graph{Path: RootModulePath}
|
||||
g.Add(&graphNodeRefParentTest{
|
||||
|
|
Loading…
Reference in New Issue