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

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/dag"
     8  )
     9  
    10  func TestPruneNoopTransformer(t *testing.T) {
    11  	g := Graph{Path: RootModulePath}
    12  
    13  	a := &testGraphNodeNoop{NameValue: "A"}
    14  	b := &testGraphNodeNoop{NameValue: "B", Value: true}
    15  	c := &testGraphNodeNoop{NameValue: "C"}
    16  
    17  	g.Add(a)
    18  	g.Add(b)
    19  	g.Add(c)
    20  	g.Connect(dag.BasicEdge(a, b))
    21  	g.Connect(dag.BasicEdge(b, c))
    22  
    23  	{
    24  		tf := &PruneNoopTransformer{}
    25  		if err := tf.Transform(&g); err != nil {
    26  			t.Fatalf("err: %s", err)
    27  		}
    28  	}
    29  
    30  	actual := strings.TrimSpace(g.String())
    31  	expected := strings.TrimSpace(testTransformPruneNoopStr)
    32  	if actual != expected {
    33  		t.Fatalf("bad:\n\n%s", actual)
    34  	}
    35  }
    36  
    37  const testTransformPruneNoopStr = `
    38  A
    39    C
    40  C
    41  `
    42  
    43  type testGraphNodeNoop struct {
    44  	NameValue string
    45  	Value     bool
    46  }
    47  
    48  func (v *testGraphNodeNoop) Name() string {
    49  	return v.NameValue
    50  }
    51  
    52  func (v *testGraphNodeNoop) Noop(*NoopOpts) bool {
    53  	return v.Value
    54  }