github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/graph_config_node_module_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/config"
     8  	"github.com/hashicorp/terraform/dag"
     9  )
    10  
    11  func TestGraphNodeConfigModule_impl(t *testing.T) {
    12  	var _ dag.Vertex = new(GraphNodeConfigModule)
    13  	var _ dag.NamedVertex = new(GraphNodeConfigModule)
    14  	var _ graphNodeConfig = new(GraphNodeConfigModule)
    15  	var _ GraphNodeExpandable = new(GraphNodeConfigModule)
    16  }
    17  
    18  func TestGraphNodeConfigModuleExpand(t *testing.T) {
    19  	mod := testModule(t, "graph-node-module-expand")
    20  
    21  	node := &GraphNodeConfigModule{
    22  		Path:   []string{RootModuleName, "child"},
    23  		Module: &config.Module{},
    24  		Tree:   nil,
    25  	}
    26  
    27  	g, err := node.Expand(&BasicGraphBuilder{
    28  		Steps: []GraphTransformer{
    29  			&ConfigTransformer{Module: mod},
    30  		},
    31  	})
    32  	if err != nil {
    33  		t.Fatalf("err: %s", err)
    34  	}
    35  
    36  	actual := strings.TrimSpace(g.Subgraph().String())
    37  	expected := strings.TrimSpace(testGraphNodeModuleExpandStr)
    38  	if actual != expected {
    39  		t.Fatalf("bad:\n\n%s", actual)
    40  	}
    41  }
    42  
    43  func TestGraphNodeConfigModuleExpandFlatten(t *testing.T) {
    44  	mod := testModule(t, "graph-node-module-flatten")
    45  
    46  	node := &GraphNodeConfigModule{
    47  		Path:   []string{RootModuleName, "child"},
    48  		Module: &config.Module{},
    49  		Tree:   nil,
    50  	}
    51  
    52  	g, err := node.Expand(&BasicGraphBuilder{
    53  		Steps: []GraphTransformer{
    54  			&ConfigTransformer{Module: mod},
    55  		},
    56  	})
    57  	if err != nil {
    58  		t.Fatalf("err: %s", err)
    59  	}
    60  
    61  	fg := g.(GraphNodeFlatGraph)
    62  
    63  	actual := strings.TrimSpace(fg.FlattenGraph().String())
    64  	expected := strings.TrimSpace(testGraphNodeModuleExpandFlattenStr)
    65  	if actual != expected {
    66  		t.Fatalf("bad:\n\n%s", actual)
    67  	}
    68  }
    69  
    70  const testGraphNodeModuleExpandStr = `
    71  aws_instance.bar
    72    aws_instance.foo
    73  aws_instance.foo
    74    module inputs
    75  module inputs
    76  plan-destroy
    77  `
    78  
    79  const testGraphNodeModuleExpandFlattenStr = `
    80  aws_instance.foo
    81  plan-destroy
    82  `