github.com/wikibal01/hashicorp-terraform@v0.11.12-beta1/terraform/transform_diff_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestDiffTransformer_nilDiff(t *testing.T) {
     9  	g := Graph{Path: RootModulePath}
    10  	tf := &DiffTransformer{}
    11  	if err := tf.Transform(&g); err != nil {
    12  		t.Fatalf("err: %s", err)
    13  	}
    14  
    15  	if len(g.Vertices()) > 0 {
    16  		t.Fatal("graph should be empty")
    17  	}
    18  }
    19  
    20  func TestDiffTransformer(t *testing.T) {
    21  	g := Graph{Path: RootModulePath}
    22  	tf := &DiffTransformer{
    23  		Module: testModule(t, "transform-diff-basic"),
    24  		Diff: &Diff{
    25  			Modules: []*ModuleDiff{
    26  				&ModuleDiff{
    27  					Path: []string{"root"},
    28  					Resources: map[string]*InstanceDiff{
    29  						"aws_instance.foo": &InstanceDiff{
    30  							Attributes: map[string]*ResourceAttrDiff{
    31  								"name": &ResourceAttrDiff{
    32  									Old: "",
    33  									New: "foo",
    34  								},
    35  							},
    36  						},
    37  					},
    38  				},
    39  			},
    40  		},
    41  	}
    42  	if err := tf.Transform(&g); err != nil {
    43  		t.Fatalf("err: %s", err)
    44  	}
    45  
    46  	actual := strings.TrimSpace(g.String())
    47  	expected := strings.TrimSpace(testTransformDiffBasicStr)
    48  	if actual != expected {
    49  		t.Fatalf("bad:\n\n%s", actual)
    50  	}
    51  }
    52  
    53  const testTransformDiffBasicStr = `
    54  aws_instance.foo
    55  `