MCPcopy Index your code
hub / github.com/devspace-sh/devspace / TestGraph

Function TestGraph

pkg/devspace/dependency/graph/graph_test.go:7–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestGraph(t *testing.T) {
8 var (
9 root = NewNode("root", nil)
10 rootChild1 = NewNode("rootChild1", nil)
11 rootChild2 = NewNode("rootChild2", nil)
12 rootChild3 = NewNode("rootChild3", nil)
13 rootChild2Child1 = NewNode("rootChild2Child1", nil)
14 rootChild2Child1Child1 = NewNode("rootChild2Child1Child1", nil)
15
16 testGraph = NewGraph(root)
17 )
18
19 _, err := testGraph.InsertNodeAt("does not exits", rootChild1.ID, nil)
20 if err == nil {
21 t.Fatal("InsertNodeAt error expected")
22 }
23
24 _, _ = testGraph.InsertNodeAt(root.ID, rootChild1.ID, nil)
25 _, _ = testGraph.InsertNodeAt(root.ID, rootChild2.ID, nil)
26 _, _ = testGraph.InsertNodeAt(root.ID, rootChild3.ID, nil)
27
28 _, _ = testGraph.InsertNodeAt(rootChild2.ID, rootChild2Child1.ID, nil)
29 _, _ = testGraph.InsertNodeAt(rootChild2Child1.ID, rootChild2Child1Child1.ID, nil)
30 _, _ = testGraph.InsertNodeAt(rootChild3.ID, rootChild2.ID, nil)
31
32 // Cyclic graph error
33 _, err = testGraph.InsertNodeAt(rootChild2Child1Child1.ID, rootChild3.ID, nil)
34 if err == nil {
35 t.Fatal("Cyclic error expected")
36 } else {
37 errMsg := `Cyclic dependency found:
38rootChild2Child1Child1
39rootChild3
40rootChild2
41rootChild2Child1
42rootChild2Child1Child1`
43
44 if err.Error() != errMsg {
45 t.Fatalf("Expected %s, got %s", errMsg, err.Error())
46 }
47 }
48
49 // Find first path
50 path := findFirstPath(rootChild1, rootChild2)
51 if path != nil {
52 t.Fatalf("Wrong path found: %#+v", path)
53 }
54
55 // Find first path
56 path = findFirstPath(root, rootChild2Child1Child1)
57 if len(path) != 4 || path[0].ID != root.ID || path[1].ID != rootChild2.ID || path[2].ID != rootChild2Child1.ID || path[3].ID != rootChild2Child1Child1.ID {
58 t.Fatalf("Wrong path found: %#+v", path)
59 }
60
61 // Get leaf node
62 leaf := testGraph.GetNextLeaf(root)
63 if leaf.ID != rootChild1.ID {
64 t.Fatalf("GetLeaf1: Got id %s, expected %s", leaf.ID, rootChild1.ID)

Callers

nothing calls this directly

Calls 10

NewGraphFunction · 0.85
findFirstPathFunction · 0.85
InsertNodeAtMethod · 0.80
GetNextLeafMethod · 0.80
AddEdgeMethod · 0.80
RemoveNodeMethod · 0.80
NewNodeFunction · 0.70
FatalMethod · 0.45
ErrorMethod · 0.45
FatalfMethod · 0.45

Tested by

no test coverage detected