github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/terraform/graph_builder_plan_test.go (about) 1 package terraform 2 3 import ( 4 "reflect" 5 "strings" 6 "testing" 7 ) 8 9 func TestPlanGraphBuilder_impl(t *testing.T) { 10 var _ GraphBuilder = new(PlanGraphBuilder) 11 } 12 13 func TestPlanGraphBuilder(t *testing.T) { 14 b := &PlanGraphBuilder{ 15 Module: testModule(t, "graph-builder-plan-basic"), 16 Providers: []string{"aws", "openstack"}, 17 DisableReduce: true, 18 } 19 20 g, err := b.Build(RootModulePath) 21 if err != nil { 22 t.Fatalf("err: %s", err) 23 } 24 25 if !reflect.DeepEqual(g.Path, RootModulePath) { 26 t.Fatalf("bad: %#v", g.Path) 27 } 28 29 actual := strings.TrimSpace(g.String()) 30 expected := strings.TrimSpace(testPlanGraphBuilderStr) 31 if actual != expected { 32 t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual) 33 } 34 } 35 36 func TestPlanGraphBuilder_targetModule(t *testing.T) { 37 b := &PlanGraphBuilder{ 38 Module: testModule(t, "graph-builder-plan-target-module-provider"), 39 Providers: []string{"null"}, 40 Targets: []string{"module.child2"}, 41 } 42 43 g, err := b.Build(RootModulePath) 44 if err != nil { 45 t.Fatalf("err: %s", err) 46 } 47 48 t.Logf("Graph: %s", g.String()) 49 50 testGraphNotContains(t, g, "module.child1.provider.null") 51 testGraphNotContains(t, g, "module.child1.null_resource.foo") 52 } 53 54 const testPlanGraphBuilderStr = ` 55 aws_instance.web 56 aws_security_group.firewall 57 provider.aws 58 var.foo 59 aws_load_balancer.weblb 60 aws_instance.web 61 provider.aws 62 aws_security_group.firewall 63 provider.aws 64 meta.count-boundary (count boundary fixup) 65 aws_instance.web 66 aws_load_balancer.weblb 67 aws_security_group.firewall 68 openstack_floating_ip.random 69 provider.aws 70 provider.openstack 71 var.foo 72 openstack_floating_ip.random 73 provider.openstack 74 provider.aws 75 openstack_floating_ip.random 76 provider.aws (close) 77 aws_instance.web 78 aws_load_balancer.weblb 79 aws_security_group.firewall 80 provider.aws 81 provider.openstack 82 provider.openstack (close) 83 openstack_floating_ip.random 84 provider.openstack 85 root 86 meta.count-boundary (count boundary fixup) 87 provider.aws (close) 88 provider.openstack (close) 89 var.foo 90 `