forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_test.go
62 lines (46 loc) · 1.09 KB
/
route_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
package buffalo
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_App_Routes_without_Root(t *testing.T) {
r := require.New(t)
a := New(Options{})
r.Nil(a.root)
a.GET("/foo", voidHandler)
routes := a.Routes()
r.Len(routes, 1)
route := routes[0]
r.Equal("GET", route.Method)
r.Equal("/foo", route.Path)
r.NotZero(route.HandlerName)
}
func Test_App_Routes_with_Root(t *testing.T) {
r := require.New(t)
a := New(Options{})
r.Nil(a.root)
g := a.Group("/api/v1")
g.GET("/foo", voidHandler)
routes := a.Routes()
r.Len(routes, 1)
route := routes[0]
r.Equal("GET", route.Method)
r.Equal("/api/v1/foo", route.Path)
r.NotZero(route.HandlerName)
r.Equal(a.Routes(), g.Routes())
}
func Test_App_RouteName(t *testing.T) {
r := require.New(t)
a := New(Options{})
cases := map[string]string{
"cool": "coolPath",
"coolPath": "coolPath",
"coco_path": "cocoPath",
"ouch_something_cool": "ouchSomethingCoolPath",
}
ri := a.GET("/something", voidHandler)
for k, v := range cases {
ri.Name(k)
r.Equal(ri.PathName, v)
}
}