-
Notifications
You must be signed in to change notification settings - Fork 10
/
router_test.go
51 lines (43 loc) · 1.11 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
// Copyright 2014 Codehack http://codehack.com
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package relax
import (
"net/url"
"testing"
)
var testRouter = newRouter()
var testRoutes = []struct {
Method string
Path string
}{
{"GET", "/posts"},
{"GET", "/posts/{uint:id}"},
{"GET", "/posts/{uint:id}/links"},
{"GET", "/posts/{word:tag}"},
{"GET", "/posts/{word:tag}/{uint:uid}"},
}
func testHandler(ctx *Context) {}
var testRequests = []struct {
Method string
Path string
Must bool
}{
{"GET", "/posts", true},
{"GET", "/posts/123", true},
{"GET", "/posts/444/links", true},
{"GET", "/posts/something", true},
{"GET", "/posts/tagged/666", true},
}
func TestFindHandler(t *testing.T) {
for i := range testRoutes {
testRouter.AddRoute(testRoutes[i].Method, testRoutes[i].Path, testHandler)
}
for i := range testRequests {
var v url.Values
_, err := testRouter.FindHandler(testRequests[i].Method, testRequests[i].Path, &v)
if testRequests[i].Must && err != nil {
t.Error(testRequests[i].Method, testRequests[i].Path, err.Error())
}
}
}