2015-01-27 06:23:27 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGraphAdd(t *testing.T) {
|
|
|
|
// Test Add since we override it and want to make sure we don't break it.
|
|
|
|
var g Graph
|
|
|
|
g.Add(42)
|
|
|
|
g.Add(84)
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testGraphAddStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
func TestGraphConnectDependent(t *testing.T) {
|
2015-01-27 06:37:10 +01:00
|
|
|
var g Graph
|
|
|
|
g.Add(&testGraphDependable{VertexName: "a", Mock: []string{"a"}})
|
2015-01-27 23:56:01 +01:00
|
|
|
b := g.Add(&testGraphDependable{
|
|
|
|
VertexName: "b",
|
|
|
|
DependentOnMock: []string{"a"},
|
|
|
|
})
|
2015-01-27 06:37:10 +01:00
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
if missing := g.ConnectDependent(b); len(missing) > 0 {
|
2015-01-27 06:37:10 +01:00
|
|
|
t.Fatalf("bad: %#v", missing)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testGraphConnectDepsStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testGraphDependable struct {
|
2015-01-27 23:56:01 +01:00
|
|
|
VertexName string
|
|
|
|
DependentOnMock []string
|
|
|
|
Mock []string
|
2015-01-27 06:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *testGraphDependable) Name() string {
|
|
|
|
return v.VertexName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *testGraphDependable) DependableName() []string {
|
|
|
|
return v.Mock
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
func (v *testGraphDependable) DependentOn() []string {
|
|
|
|
return v.DependentOnMock
|
|
|
|
}
|
|
|
|
|
2015-01-27 06:23:27 +01:00
|
|
|
const testGraphAddStr = `
|
|
|
|
42
|
|
|
|
84
|
|
|
|
`
|
2015-01-27 06:37:10 +01:00
|
|
|
|
|
|
|
const testGraphConnectDepsStr = `
|
|
|
|
a
|
|
|
|
b
|
|
|
|
a
|
|
|
|
`
|