github.com/ns1/terraform@v0.7.10-0.20161109153551-8949419bef40/terraform/graph_builder_apply_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestApplyGraphBuilder_impl(t *testing.T) {
    10  	var _ GraphBuilder = new(ApplyGraphBuilder)
    11  }
    12  
    13  func TestApplyGraphBuilder(t *testing.T) {
    14  	diff := &Diff{
    15  		Modules: []*ModuleDiff{
    16  			&ModuleDiff{
    17  				Path: []string{"root"},
    18  				Resources: map[string]*InstanceDiff{
    19  					// Verify noop doesn't show up in graph
    20  					"aws_instance.noop": &InstanceDiff{},
    21  
    22  					"aws_instance.create": &InstanceDiff{
    23  						Attributes: map[string]*ResourceAttrDiff{
    24  							"name": &ResourceAttrDiff{
    25  								Old: "",
    26  								New: "foo",
    27  							},
    28  						},
    29  					},
    30  
    31  					"aws_instance.other": &InstanceDiff{
    32  						Attributes: map[string]*ResourceAttrDiff{
    33  							"name": &ResourceAttrDiff{
    34  								Old: "",
    35  								New: "foo",
    36  							},
    37  						},
    38  					},
    39  				},
    40  			},
    41  
    42  			&ModuleDiff{
    43  				Path: []string{"root", "child"},
    44  				Resources: map[string]*InstanceDiff{
    45  					"aws_instance.create": &InstanceDiff{
    46  						Attributes: map[string]*ResourceAttrDiff{
    47  							"name": &ResourceAttrDiff{
    48  								Old: "",
    49  								New: "foo",
    50  							},
    51  						},
    52  					},
    53  
    54  					"aws_instance.other": &InstanceDiff{
    55  						Attributes: map[string]*ResourceAttrDiff{
    56  							"name": &ResourceAttrDiff{
    57  								Old: "",
    58  								New: "foo",
    59  							},
    60  						},
    61  					},
    62  				},
    63  			},
    64  		},
    65  	}
    66  
    67  	b := &ApplyGraphBuilder{
    68  		Module:        testModule(t, "graph-builder-apply-basic"),
    69  		Diff:          diff,
    70  		Providers:     []string{"aws"},
    71  		Provisioners:  []string{"exec"},
    72  		DisableReduce: true,
    73  	}
    74  
    75  	g, err := b.Build(RootModulePath)
    76  	if err != nil {
    77  		t.Fatalf("err: %s", err)
    78  	}
    79  
    80  	if !reflect.DeepEqual(g.Path, RootModulePath) {
    81  		t.Fatalf("bad: %#v", g.Path)
    82  	}
    83  
    84  	actual := strings.TrimSpace(g.String())
    85  	expected := strings.TrimSpace(testApplyGraphBuilderStr)
    86  	if actual != expected {
    87  		t.Fatalf("bad: %s", actual)
    88  	}
    89  }
    90  
    91  const testApplyGraphBuilderStr = `
    92  aws_instance.create
    93    provider.aws
    94  aws_instance.other
    95    aws_instance.create
    96    provider.aws
    97  meta.count-boundary (count boundary fixup)
    98    aws_instance.create
    99    aws_instance.other
   100    module.child.aws_instance.create
   101    module.child.aws_instance.other
   102    module.child.provider.aws
   103    module.child.provisioner.exec
   104    provider.aws
   105  module.child.aws_instance.create
   106    module.child.provider.aws
   107    module.child.provisioner.exec
   108  module.child.aws_instance.other
   109    module.child.aws_instance.create
   110    module.child.provider.aws
   111  module.child.provider.aws
   112    provider.aws
   113  module.child.provisioner.exec
   114  provider.aws
   115  `