-
Notifications
You must be signed in to change notification settings - Fork 0
/
depgraph_test.go
38 lines (28 loc) · 1.1 KB
/
depgraph_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package errgoengine
import (
"testing"
testutils "github.com/nedpals/errgoengine/test_utils"
)
func TestDepGraph(t *testing.T) {
graph := DepGraph{}
// Adding
graph.Add("a", map[string]string{"b": "c"})
graph.Add("d", map[string]string{"e": "c"})
testutils.Equals(t, graph.Has("a"), true)
testutils.Equals(t, graph.Has("c"), true)
testutils.Equals(t, graph["a"].Path, "a")
testutils.EqualsMap(t, graph["a"].Graph, graph)
testutils.EqualsMap(t, graph["a"].Dependencies, map[string]string{"b": "c"})
testutils.Equals(t, graph["d"].Path, "d")
testutils.EqualsMap(t, graph["d"].Graph, graph)
testutils.EqualsMap(t, graph["d"].Dependencies, map[string]string{"e": "c"})
testutils.EqualsList(t, graph["c"].DependentPaths(), []string{"a", "d"})
// Deleting
testutils.ExpectNoError(t, graph.Detach("d", "c"))
testutils.Equals(t, graph.Has("d"), true)
testutils.Equals(t, graph.Has("c"), true)
testutils.EqualsList(t, graph["c"].DependentPaths(), []string{"a"})
testutils.ExpectNoError(t, graph.Detach("a", "c"))
testutils.Equals(t, graph.Has("a"), true)
testutils.Equals(t, graph.Has("c"), false)
}