From d61f199d6fc600fd8b4dd8a155a9512260b7ec69 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 18 Sep 2014 11:12:39 -0700 Subject: [PATCH] terraform: test dependency encoding --- terraform/graph_test.go | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/terraform/graph_test.go b/terraform/graph_test.go index 9d27b7cb6..0623c347a 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -354,6 +354,50 @@ func TestGraphAddDiff_destroy(t *testing.T) { } } +func TestEncodeDependencies(t *testing.T) { + config := testConfig(t, "graph-basic") + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.web": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + "aws_load_balancer.weblb": &ResourceState{ + Type: "aws_load_balancer", + Primary: &InstanceState{ + ID: "foo", + }, + }, + }, + }, + }, + } + + g, err := Graph(&GraphOpts{Config: config, State: state}) + if err != nil { + t.Fatalf("err: %s", err) + } + + // This should encode the dependency information into the state + EncodeDependencies(g) + + root := state.RootModule() + web := root.Resources["aws_instance.web"] + if len(web.Dependencies) != 1 || web.Dependencies[0] != "aws_security_group.firewall" { + t.Fatalf("bad: %#v", web) + } + + weblb := root.Resources["aws_load_balancer.weblb"] + if len(weblb.Dependencies) != 1 || weblb.Dependencies[0] != "aws_instance.web" { + t.Fatalf("bad: %#v", weblb) + } +} + const testTerraformGraphStr = ` root: root aws_instance.web