github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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("bad: %s", 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 openstack_floating_ip.random 65 provider.openstack 66 provider.aws 67 openstack_floating_ip.random 68 provider.openstack 69 var.foo 70 `