-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_test.go
90 lines (82 loc) · 1.89 KB
/
graph_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package viz
import (
"testing"
"github.com/cybozu-go/placemat"
)
func TestGenerate(t *testing.T) {
graph := NewVisualizer()
g, err := graph.Generate(&ClusterSpec{})
if err != nil {
t.Fatal(err)
}
if len(g.Edges.Edges) != 0 {
t.Error(err)
}
net1 := "net1"
net2 := "swith-to-nodes"
pods := []*placemat.PodSpec{
{
Name: "switch1",
Interfaces: []placemat.PodInterfaceSpec{
{
Network: net1,
Addresses: []string{"1.1.1.1/32"},
},
},
},
{
Name: "switch2",
Interfaces: []placemat.PodInterfaceSpec{
{
Network: net1,
Addresses: []string{"1.1.1.1/32"},
},
{
Network: net2,
Addresses: []string{"10.0.10.0/26"},
},
},
},
}
g, err = NewVisualizer().Generate(&ClusterSpec{Pods: pods})
if err != nil {
t.Fatal(err)
}
if len(g.Edges.Edges) != 1 {
t.Error("should have one edge, actual:", len(g.Edges.Edges))
}
g, err = NewVisualizer().Generate(&ClusterSpec{Pods: pods[:1]})
if err != nil {
t.Fatal(err)
}
if len(g.Edges.Edges) != 0 {
t.Error("should have no edge, actual:", len(g.Edges.Edges))
}
nodes := []*placemat.NodeSpec{
{Name: "node1", Interfaces: []string{net2}},
{Name: "node2", Interfaces: []string{net2}},
}
g, err = NewVisualizer().Generate(&ClusterSpec{Pods: pods, Nodes: nodes})
if err != nil {
t.Fatal(err)
}
if len(g.Edges.Edges) != 3 {
t.Error("should have 3 edge, actual:", len(g.Edges.Edges))
}
if len(g.Nodes.Nodes) != 4 {
t.Error("should have 4 nodes, actual:", len(g.Nodes.Nodes))
}
if len(g.SubGraphs.SubGraphs) != 1 {
t.Error("should have 1 sub graphs, actual:", len(g.SubGraphs.SubGraphs))
}
g, err = NewVisualizer().Generate(&ClusterSpec{Nodes: nodes})
if err != nil {
t.Fatal(err)
}
if len(g.Edges.Edges) != 0 {
t.Error("should have 0 edge, actual:", len(g.Edges.Edges))
}
if len(g.Nodes.Nodes) != 2 {
t.Error("should have 2 nodes, actual:", len(g.Nodes.Nodes))
}
}