forked from julienschmidt/go-http-routing-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routers_test.go
91 lines (83 loc) · 1.91 KB
/
routers_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
var (
// load functions of all routers
routers = []struct {
name string
load func(routes []route) http.Handler
}{
{"Ace", loadAce},
{"Aero", loadAero},
{"Bear", loadBear},
{"Beego", loadBeego},
{"Bone", loadBone},
{"Chi", loadChi},
{"CloudyKitRouter", loadCloudyKitRouter},
{"Denco", loadDenco},
{"Echo", loadEcho},
{"Gin", loadGin},
{"GocraftWeb", loadGocraftWeb},
{"Goji", loadGoji},
{"Gojiv2", loadGojiv2},
{"GoJsonRest", loadGoJsonRest},
{"GoRestful", loadGoRestful},
{"GorillaMux", loadGorillaMux},
{"GowwwRouter", loadGowwwRouter},
{"HttpRouter", loadHttpRouter},
{"HttpTreeMux", loadHttpTreeMux},
//{"Kocha", loadKocha},
{"LARS", loadLARS},
{"Macaron", loadMacaron},
{"Martini", loadMartini},
{"Pat", loadPat},
{"Possum", loadPossum},
{"R2router", loadR2router},
// {"Revel", loadRevel},
{"Rivet", loadRivet},
//{"Tango", loadTango},
{"TigerTonic", loadTigerTonic},
{"Traffic", loadTraffic},
{"Vulcan", loadVulcan},
// {"Zeus", loadZeus},
}
// all APIs
apis = []struct {
name string
routes []route
}{
{"GitHub", githubAPI},
{"GPlus", gplusAPI},
{"Parse", parseAPI},
{"Static", staticRoutes},
}
)
func TestRouters(t *testing.T) {
loadTestHandler = true
for _, router := range routers {
req, _ := http.NewRequest("GET", "/", nil)
u := req.URL
rq := u.RawQuery
for _, api := range apis {
r := router.load(api.routes)
for _, route := range api.routes {
w := httptest.NewRecorder()
req.Method = route.method
req.RequestURI = route.path
u.Path = route.path
u.RawQuery = rq
r.ServeHTTP(w, req)
if w.Code != 200 || w.Body.String() != route.path {
t.Errorf(
"%s in API %s: %d - %s; expected %s %s\n",
router.name, api.name, w.Code, w.Body.String(), route.method, route.path,
)
}
}
}
}
loadTestHandler = false
}