github.com/ctrox/terraform@v0.11.12-beta1/terraform/graph_builder_refresh_test.go (about)

     1  package terraform
     2  
     3  import "testing"
     4  
     5  func TestRefreshGraphBuilder_configOrphans(t *testing.T) {
     6  
     7  	m := testModule(t, "refresh-config-orphan")
     8  
     9  	state := &State{
    10  		Modules: []*ModuleState{
    11  			&ModuleState{
    12  				Path: rootModulePath,
    13  				Resources: map[string]*ResourceState{
    14  					"aws_instance.foo.0": &ResourceState{
    15  						Type: "aws_instance",
    16  						Deposed: []*InstanceState{
    17  							&InstanceState{
    18  								ID: "foo",
    19  							},
    20  						},
    21  					},
    22  					"aws_instance.foo.1": &ResourceState{
    23  						Type: "aws_instance",
    24  						Deposed: []*InstanceState{
    25  							&InstanceState{
    26  								ID: "bar",
    27  							},
    28  						},
    29  					},
    30  					"aws_instance.foo.2": &ResourceState{
    31  						Type: "aws_instance",
    32  						Deposed: []*InstanceState{
    33  							&InstanceState{
    34  								ID: "baz",
    35  							},
    36  						},
    37  					},
    38  					"data.aws_instance.foo.0": &ResourceState{
    39  						Type: "aws_instance",
    40  						Deposed: []*InstanceState{
    41  							&InstanceState{
    42  								ID: "foo",
    43  							},
    44  						},
    45  					},
    46  					"data.aws_instance.foo.1": &ResourceState{
    47  						Type: "aws_instance",
    48  						Deposed: []*InstanceState{
    49  							&InstanceState{
    50  								ID: "bar",
    51  							},
    52  						},
    53  					},
    54  					"data.aws_instance.foo.2": &ResourceState{
    55  						Type: "aws_instance",
    56  						Deposed: []*InstanceState{
    57  							&InstanceState{
    58  								ID: "baz",
    59  							},
    60  						},
    61  					},
    62  				},
    63  			},
    64  		},
    65  	}
    66  
    67  	b := &RefreshGraphBuilder{
    68  		Module:    m,
    69  		State:     state,
    70  		Providers: []string{"aws"},
    71  	}
    72  	g, err := b.Build(rootModulePath)
    73  	if err != nil {
    74  		t.Fatalf("Error building graph: %s", err)
    75  	}
    76  
    77  	actual := g.StringWithNodeTypes()
    78  	expected := `aws_instance.foo - *terraform.NodeRefreshableManagedResource
    79    provider.aws - *terraform.NodeApplyableProvider
    80  data.aws_instance.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
    81    provider.aws - *terraform.NodeApplyableProvider
    82  data.aws_instance.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
    83    provider.aws - *terraform.NodeApplyableProvider
    84  data.aws_instance.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
    85    provider.aws - *terraform.NodeApplyableProvider
    86  provider.aws - *terraform.NodeApplyableProvider
    87  provider.aws (close) - *terraform.graphNodeCloseProvider
    88    aws_instance.foo - *terraform.NodeRefreshableManagedResource
    89    data.aws_instance.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
    90    data.aws_instance.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
    91    data.aws_instance.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
    92  `
    93  	if expected != actual {
    94  		t.Fatalf("Expected:\n%s\nGot:\n%s", expected, actual)
    95  	}
    96  }