terraform: reference transformer shouldn't make loop to self

This commit is contained in:
Mitchell Hashimoto 2016-09-18 21:31:03 -07:00
parent 5018617049
commit 38b9f7794d
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 35 additions and 0 deletions

View File

@ -88,6 +88,18 @@ func (m *ReferenceMap) References(v dag.Vertex) ([]dag.Vertex, []string) {
continue 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...) matches = append(matches, parents...)
} }

View File

@ -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) { func TestReferenceTransformer_path(t *testing.T) {
g := Graph{Path: RootModulePath} g := Graph{Path: RootModulePath}
g.Add(&graphNodeRefParentTest{ g.Add(&graphNodeRefParentTest{