-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_test.go
64 lines (56 loc) · 1.44 KB
/
router_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
package jago
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestJagoStatic(t *testing.T) {
g := New()
loadJagoRoutes(g, parseAPI)
r := g.router
c := g.NewContext(nil, nil)
r.find("/1/users/", "GET", c)
assert.Equal(t, "/1/users", c.Path())
}
func TestJagoParam1(t *testing.T) {
g := New()
loadJagoRoutes(g, parseAPI)
r := g.router
c := g.NewContext(nil, nil)
r.find("/1/classes/a/Obj", "GET", c)
assert.Equal(t, "/1/classes/:className/:objectId", c.Path())
assert.Equal(t, "a", c.Param("className"))
assert.Equal(t, "Obj", c.Param("objectId"))
}
func TestJagoParam2(t *testing.T) {
g := New()
loadJagoRoutes(g, parseAPI)
r := g.router
c := g.NewContext(nil, nil)
r.find("/1/classes/a/Obj", "POST", c)
assert.Equal(t, "", c.Path())
}
func TestJagoParam3(t *testing.T) {
g := New()
loadJagoRoutes(g, parseAPI)
r := g.router
c := g.NewContext(nil, nil)
r.find("/1/classes/Category/Item", "GET", c)
assert.Equal(t, "/1/:type/Category/Item", c.Path())
assert.Equal(t, "classes", c.Param("type"))
}
func TestJagoWildcard1(t *testing.T) {
g := New()
loadJagoRoutes(g, parseAPI)
r := g.router
c := g.NewContext(nil, nil)
r.find("/1/functions/", "GET", c)
assert.Equal(t, "/1/functions/*", c.Path())
}
func TestJagoWildcard2(t *testing.T) {
g := New()
loadJagoRoutes(g, parseAPI)
r := g.router
c := g.NewContext(nil, nil)
r.find("/1/functions/funcA/hello-world", "GET", c)
assert.Equal(t, "/1/functions/*", c.Path())
}