github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/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  local.instance_id
    65    aws_instance.web
    66  meta.count-boundary (count boundary fixup)
    67    aws_instance.web
    68    aws_load_balancer.weblb
    69    aws_security_group.firewall
    70    local.instance_id
    71    openstack_floating_ip.random
    72    output.instance_id
    73    provider.aws
    74    provider.openstack
    75    var.foo
    76  openstack_floating_ip.random
    77    provider.openstack
    78  output.instance_id
    79    local.instance_id
    80  provider.aws
    81    openstack_floating_ip.random
    82  provider.aws (close)
    83    aws_instance.web
    84    aws_load_balancer.weblb
    85    aws_security_group.firewall
    86    provider.aws
    87  provider.openstack
    88  provider.openstack (close)
    89    openstack_floating_ip.random
    90    provider.openstack
    91  root
    92    meta.count-boundary (count boundary fixup)
    93    provider.aws (close)
    94    provider.openstack (close)
    95  var.foo
    96  `