-
Notifications
You must be signed in to change notification settings - Fork 28
/
draft_test.go
68 lines (55 loc) · 1.19 KB
/
draft_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
package draft
import (
"fmt"
"strings"
"testing"
"github.com/emicklei/dot"
)
func TestIDAutoGen(t *testing.T) {
tests := []struct {
kind string
want string
}{
{kindCDN, "cdn1"},
{kindCDN, "cdn2"},
{kindCDN, "cdn3"},
{kindService, "ser1"},
{kindService, "ser2"},
{kindCDN, "cdn4"},
{kindService, "ser3"},
}
gen := idAutoGen()
for _, tt := range tests {
com := Component{Kind: tt.kind}
t.Run(tt.kind, func(t *testing.T) {
gen(&com)
if got := com.ID; got != tt.want {
t.Errorf("got [%v] want [%v]", got, tt.want)
}
})
}
}
func TestSketchComponents(t *testing.T) {
gfx := dot.NewGraph(dot.Directed)
items := []Component{
{Kind: kindGateway},
{Kind: kindFunction},
}
if err := sketchComponents(gfx, Config{}, items); err != nil {
t.Error(err)
}
if n, ok := gfx.FindNodeById("gtw1"); ok {
got := fmt.Sprintf("%v", n.Value("label"))
want := "default/gtw.png"
if !strings.Contains(got, want) {
t.Errorf("got [%v] want [%v]", got, want)
}
}
if n, ok := gfx.FindNodeById("fun1"); ok {
got := fmt.Sprintf("%v", n.Value("label"))
want := "default/fun.png"
if !strings.Contains(got, want) {
t.Errorf("got [%v] want [%v]", got, want)
}
}
}