github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/terraform/transform_flatten_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestFlattenTransformer(t *testing.T) {
     9  	mod := testModule(t, "transform-flatten")
    10  
    11  	var b BasicGraphBuilder
    12  	b = BasicGraphBuilder{
    13  		Steps: []GraphTransformer{
    14  			&ConfigTransformer{Module: mod},
    15  			&VertexTransformer{
    16  				Transforms: []GraphVertexTransformer{
    17  					&ExpandTransform{
    18  						Builder: &b,
    19  					},
    20  				},
    21  			},
    22  			&FlattenTransformer{},
    23  		},
    24  	}
    25  
    26  	g, err := b.Build(rootModulePath)
    27  	if err != nil {
    28  		t.Fatalf("err: %s", err)
    29  	}
    30  
    31  	actual := strings.TrimSpace(g.String())
    32  	expected := strings.TrimSpace(testTransformFlattenStr)
    33  	if actual != expected {
    34  		t.Fatalf("bad:\n\n%s", actual)
    35  	}
    36  }
    37  
    38  func TestFlattenTransformer_withProxy(t *testing.T) {
    39  	mod := testModule(t, "transform-flatten")
    40  
    41  	var b BasicGraphBuilder
    42  	b = BasicGraphBuilder{
    43  		Steps: []GraphTransformer{
    44  			&ConfigTransformer{Module: mod},
    45  			&VertexTransformer{
    46  				Transforms: []GraphVertexTransformer{
    47  					&ExpandTransform{
    48  						Builder: &b,
    49  					},
    50  				},
    51  			},
    52  			&FlattenTransformer{},
    53  			&ProxyTransformer{},
    54  		},
    55  	}
    56  
    57  	g, err := b.Build(rootModulePath)
    58  	if err != nil {
    59  		t.Fatalf("err: %s", err)
    60  	}
    61  
    62  	actual := strings.TrimSpace(g.String())
    63  	expected := strings.TrimSpace(testTransformFlattenProxyStr)
    64  	if actual != expected {
    65  		t.Fatalf("bad:\n\n%s", actual)
    66  	}
    67  }
    68  
    69  const testTransformFlattenStr = `
    70  aws_instance.parent
    71  aws_instance.parent-output
    72    module.child.output.output
    73  module.child.aws_instance.child
    74    module.child.var.var
    75  module.child.output.output
    76    module.child.aws_instance.child
    77  module.child.plan-destroy
    78  module.child.var.var
    79    aws_instance.parent
    80  `
    81  
    82  const testTransformFlattenProxyStr = `
    83  aws_instance.parent
    84  aws_instance.parent-output
    85    module.child.aws_instance.child
    86    module.child.output.output
    87  module.child.aws_instance.child
    88    aws_instance.parent
    89    module.child.var.var
    90  module.child.output.output
    91    module.child.aws_instance.child
    92  module.child.plan-destroy
    93  module.child.var.var
    94    aws_instance.parent
    95  `