Skip to content

Commit 460e65b

Browse files
committed
tree_test
tree test class: #1
1 parent e4fb44d commit 460e65b

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tree_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package godzilla
22

3+
import "testing"
4+
35
func catchPanic(f func()) (recv interface{}) {
46
defer func() {
57
recv = recover()
@@ -14,3 +16,56 @@ type testRouter struct {
1416
path string
1517
conflict bool
1618
}
19+
20+
func TestAddRoute(t *testing.T) {
21+
tree := createRootNode()
22+
23+
routes := []testRoute{
24+
{"/cmd/:tool/:sub", false},
25+
{"/cmd/vet", true},
26+
{"/src/*", false},
27+
{"/src/*", true},
28+
{"/src/test", true},
29+
{"/src/:test", true},
30+
{"/src/", false},
31+
{"/src1/", false},
32+
{"/src1/*", false},
33+
{"/search/:query", false},
34+
{"/search/invalid", true},
35+
{"/user_:name", false},
36+
{"/user_x", false},
37+
{"/id:id", false},
38+
{"/id/:id", false},
39+
{"/id/:value", true},
40+
{"/id/:id/settings", false},
41+
{"/id/:id/:type", true},
42+
{"/*", true},
43+
{"books/*/get", true},
44+
{"/file/test", false},
45+
{"/file/test", true},
46+
{"/file/:test", true},
47+
{"/orders/:id/settings/:id", true},
48+
{"/accounts/*/settings", true},
49+
{"/results/*", false},
50+
{"/results/*/view", true},
51+
}
52+
for _, route := range routes {
53+
recv := catchPanic(func() {
54+
tree.addRoute(route.path, emptyHandlersChain)
55+
})
56+
57+
if route.conflict {
58+
if recv == nil {
59+
t.Errorf("no panic for conflicting route '%s'", route.path)
60+
}
61+
} else if recv != nil {
62+
t.Errorf("unexpected panic for route '%s': %v", route.path, recv)
63+
}
64+
}
65+
}
66+
67+
type testRequest []struct {
68+
path string
69+
match bool
70+
params map[string]string
71+
}

0 commit comments

Comments
 (0)