-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_test.go
59 lines (52 loc) · 924 Bytes
/
tree_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
package gRouter
import (
"testing"
)
func handlerTest(c *Context) {
}
var urlsTest = []string{
"/",
"/0",
"/0/1",
"/0/2",
"/0/1/3",
"/0/1/3/7",
"/0/1/3/8",
"/0/1/4",
"/0/1/4/9",
"/0/1/4/10",
"/0/2/5",
"/0/2/5/11",
"/0/2/5/12",
"/0/2/6",
"/0/2/6/13",
"/0/2/6/14",
"/0/2/6/14/19/20/400",
}
func createTree() *tree {
tree := newTree("POST")
for _, url := range urlsTest {
tree.Add(url, HandlersChain{handlerTest})
}
return tree
}
func TestTree_Add(t *testing.T) {
tree := createTree()
pathList := tree.PathList()
if !StringSortEqual(urlsTest, pathList) {
t.Fatal("createTree error")
}
}
func TestTree_Find(t *testing.T) {
tree := createTree()
for _, url := range urlsTest {
handlers, err := tree.Find(url)
if err != nil {
t.Fatalf("url=%v, error=%v", url, err)
}
if len(handlers) == 0 {
t.Fatalf("url=%v, error=not found", url)
}
}
t.Logf("%v success", len(urlsTest))
}