github.com/adrian-bl/terraform@v0.7.0-rc2.0.20160705220747-de0a34fc3517/terraform/transform_expand_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/terraform/dag" 8 ) 9 10 func TestExpandTransform_impl(t *testing.T) { 11 var _ GraphVertexTransformer = new(ExpandTransform) 12 } 13 14 func TestExpandTransform(t *testing.T) { 15 var g Graph 16 g.Add(1) 17 g.Add(2) 18 g.Connect(dag.BasicEdge(1, 2)) 19 20 tf := &ExpandTransform{} 21 out, err := tf.Transform(&testExpandable{ 22 Result: &g, 23 }) 24 if err != nil { 25 t.Fatalf("err: %s", err) 26 } 27 28 sn, ok := out.(GraphNodeSubgraph) 29 if !ok { 30 t.Fatalf("not subgraph: %#v", out) 31 } 32 33 actual := strings.TrimSpace(sn.Subgraph().String()) 34 expected := strings.TrimSpace(testExpandTransformStr) 35 if actual != expected { 36 t.Fatalf("bad: %s", actual) 37 } 38 } 39 40 func TestExpandTransform_nonExpandable(t *testing.T) { 41 tf := &ExpandTransform{} 42 out, err := tf.Transform(42) 43 if err != nil { 44 t.Fatalf("err: %s", err) 45 } 46 if out != 42 { 47 t.Fatalf("bad: %#v", out) 48 } 49 } 50 51 type testExpandable struct { 52 // Inputs 53 Result *Graph 54 ResultError error 55 56 // Outputs 57 Builder GraphBuilder 58 } 59 60 func (n *testExpandable) Expand(b GraphBuilder) (GraphNodeSubgraph, error) { 61 n.Builder = b 62 return &testSubgraph{n.Result}, n.ResultError 63 } 64 65 type testSubgraph struct { 66 Graph *Graph 67 } 68 69 func (n *testSubgraph) Subgraph() *Graph { 70 return n.Graph 71 } 72 73 const testExpandTransformStr = ` 74 1 75 2 76 2 77 `