forked from goccy/go-graphviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphviz_test.go
82 lines (78 loc) · 1.7 KB
/
graphviz_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
package graphviz_test
import (
"bytes"
"testing"
"github.com/goccy/go-graphviz"
)
func TestGraphviz_Image(t *testing.T) {
g := graphviz.New()
graph, err := g.Graph()
if err != nil {
t.Fatalf("%+v", err)
}
defer func() {
graph.Close()
g.Close()
}()
n, err := graph.CreateNode("n")
if err != nil {
t.Fatalf("%+v", err)
}
m, err := graph.CreateNode("m")
if err != nil {
t.Fatalf("%+v", err)
}
e, err := graph.CreateEdge("e", n, m)
if err != nil {
t.Fatalf("%+v", err)
}
e.SetLabel("e")
t.Run("png", func(t *testing.T) {
t.Run("Render", func(t *testing.T) {
var buf bytes.Buffer
if err := g.Render(graph, graphviz.PNG, &buf); err != nil {
t.Fatalf("%+v", err)
}
if len(buf.Bytes()) != 4602 {
t.Fatalf("failed to encode png: bytes length is %d", len(buf.Bytes()))
}
})
t.Run("RenderImage", func(t *testing.T) {
image, err := g.RenderImage(graph)
if err != nil {
t.Fatalf("%+v", err)
}
bounds := image.Bounds()
if bounds.Max.X != 83 {
t.Fatal("failed to get image")
}
if bounds.Max.Y != 177 {
t.Fatal("failed to get image")
}
})
})
t.Run("jpg", func(t *testing.T) {
t.Run("Render", func(t *testing.T) {
var buf bytes.Buffer
if err := g.Render(graph, graphviz.JPG, &buf); err != nil {
t.Fatalf("%+v", err)
}
if len(buf.Bytes()) != 3296 {
t.Fatalf("failed to encode jpg: bytes length is %d", len(buf.Bytes()))
}
})
t.Run("RenderImage", func(t *testing.T) {
image, err := g.RenderImage(graph)
if err != nil {
t.Fatalf("%+v", err)
}
bounds := image.Bounds()
if bounds.Max.X != 83 {
t.Fatal("failed to get image")
}
if bounds.Max.Y != 177 {
t.Fatal("failed to get image")
}
})
})
}