Skip to content

Commit cb4e364

Browse files
committed
terraform: more tests
1 parent 4f8152c commit cb4e364

4 files changed

Lines changed: 44 additions & 87 deletions

File tree

‎terraform/graph.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func (g *Graph) Add(v dag.Vertex) dag.Vertex {
5656
func (g *Graph) ConnectTo(source dag.Vertex, target []string) []string {
5757
g.once.Do(g.init)
5858

59-
// TODO: test
6059
var missing []string
6160
for _, t := range target {
6261
if dest := g.dependableMap[t]; dest != nil {
@@ -78,3 +77,12 @@ func (g *Graph) init() {
7877
g.dependableMap = make(map[string]dag.Vertex)
7978
}
8079
}
80+
81+
// GraphNodeDependable is an interface which says that a node can be
82+
// depended on (an edge can be placed between this node and another) according
83+
// to the well-known name returned by DependableName.
84+
//
85+
// DependableName can return multiple names it is known by.
86+
type GraphNodeDependable interface {
87+
DependableName() []string
88+
}

‎terraform/graph_deps.go‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎terraform/graph_deps_test.go‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎terraform/graph_test.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,42 @@ func TestGraphAdd(t *testing.T) {
1818
}
1919
}
2020

21+
func TestGraphConnectTo(t *testing.T) {
22+
var g Graph
23+
g.Add(&testGraphDependable{VertexName: "a", Mock: []string{"a"}})
24+
b := g.Add(&testGraphDependable{VertexName: "b"})
25+
26+
if missing := g.ConnectTo(b, []string{"a"}); len(missing) > 0 {
27+
t.Fatalf("bad: %#v", missing)
28+
}
29+
30+
actual := strings.TrimSpace(g.String())
31+
expected := strings.TrimSpace(testGraphConnectDepsStr)
32+
if actual != expected {
33+
t.Fatalf("bad: %s", actual)
34+
}
35+
}
36+
37+
type testGraphDependable struct {
38+
VertexName string
39+
Mock []string
40+
}
41+
42+
func (v *testGraphDependable) Name() string {
43+
return v.VertexName
44+
}
45+
46+
func (v *testGraphDependable) DependableName() []string {
47+
return v.Mock
48+
}
49+
2150
const testGraphAddStr = `
2251
42
2352
84
2453
`
54+
55+
const testGraphConnectDepsStr = `
56+
a
57+
b
58+
a
59+
`

0 commit comments

Comments
 (0)