terraform: passing test for destroy edge for module only

Just adding passing tests as a sanity check for a bug.
This commit is contained in:
Mitchell Hashimoto 2017-02-07 19:12:03 -08:00
parent ac3d67e40f
commit af61d566c2
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,8 @@
resource "aws_instance" "a" {}
resource "aws_instance" "b" {
value = "${aws_instance.a.id}"
}
resource "aws_instance" "c" {
value = "${aws_instance.b.id}"
}

View File

@ -0,0 +1,3 @@
module "child" {
source = "./child"
}

View File

@ -45,12 +45,11 @@ func (t *AttachStateTransformer) Transform(g *Graph) error {
} }
// Attach the first resource state we get // Attach the first resource state we get
log.Printf("SEARCH: %s", addr)
found := false found := false
for _, result := range results { for _, result := range results {
if rs, ok := result.Value.(*ResourceState); ok { if rs, ok := result.Value.(*ResourceState); ok {
log.Printf( log.Printf(
"[DEBUG] Attaching resource state to %q: %s", "[DEBUG] Attaching resource state to %q: %#v",
dag.VertexName(v), rs) dag.VertexName(v), rs)
an.AttachResourceState(rs) an.AttachResourceState(rs)
found = true found = true

View File

@ -96,6 +96,32 @@ func TestDestroyEdgeTransformer_module(t *testing.T) {
} }
} }
func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
g := Graph{Path: RootModulePath}
g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.a"})
g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.b"})
g.Add(&graphNodeDestroyerTest{AddrString: "module.child.aws_instance.c"})
tf := &DestroyEdgeTransformer{
Module: testModule(t, "transform-destroy-edge-module-only"),
}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(`
module.child.aws_instance.a (destroy)
module.child.aws_instance.b (destroy)
module.child.aws_instance.c (destroy)
module.child.aws_instance.b (destroy)
module.child.aws_instance.c (destroy)
module.child.aws_instance.c (destroy)
`)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
type graphNodeCreatorTest struct { type graphNodeCreatorTest struct {
AddrString string AddrString string
Refs []string Refs []string