github.com/bendemaree/terraform@v0.5.4-0.20150613200311-f50d97d6eee6/terraform/graph_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestGraphAdd(t *testing.T) { 9 // Test Add since we override it and want to make sure we don't break it. 10 var g Graph 11 g.Add(42) 12 g.Add(84) 13 14 actual := strings.TrimSpace(g.String()) 15 expected := strings.TrimSpace(testGraphAddStr) 16 if actual != expected { 17 t.Fatalf("bad: %s", actual) 18 } 19 } 20 21 func TestGraphConnectDependent(t *testing.T) { 22 var g Graph 23 g.Add(&testGraphDependable{VertexName: "a", Mock: []string{"a"}}) 24 b := g.Add(&testGraphDependable{ 25 VertexName: "b", 26 DependentOnMock: []string{"a"}, 27 }) 28 29 if missing := g.ConnectDependent(b); len(missing) > 0 { 30 t.Fatalf("bad: %#v", missing) 31 } 32 33 actual := strings.TrimSpace(g.String()) 34 expected := strings.TrimSpace(testGraphConnectDepsStr) 35 if actual != expected { 36 t.Fatalf("bad: %s", actual) 37 } 38 } 39 40 type testGraphDependable struct { 41 VertexName string 42 DependentOnMock []string 43 Mock []string 44 } 45 46 func (v *testGraphDependable) Name() string { 47 return v.VertexName 48 } 49 50 func (v *testGraphDependable) DependableName() []string { 51 return v.Mock 52 } 53 54 func (v *testGraphDependable) DependentOn() []string { 55 return v.DependentOnMock 56 } 57 58 const testGraphAddStr = ` 59 42 60 84 61 ` 62 63 const testGraphConnectDepsStr = ` 64 a 65 b 66 a 67 `