-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathpprof_test.go
55 lines (48 loc) · 1.4 KB
/
pprof_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
package ginpprof
import (
"strings"
"testing"
"github.com/gin-gonic/gin"
)
func newServer() *gin.Engine {
r := gin.Default()
return r
}
func checkRouters(routers gin.RoutesInfo, t *testing.T) {
expectedRouters := map[string]string{
"/debug/pprof/": "IndexHandler",
"/debug/pprof/heap": "HeapHandler",
"/debug/pprof/goroutine": "GoroutineHandler",
"/debug/pprof/allocs": "AllocsHandler",
"/debug/pprof/block": "BlockHandler",
"/debug/pprof/threadcreate": "ThreadCreateHandler",
"/debug/pprof/cmdline": "CmdlineHandler",
"/debug/pprof/profile": "ProfileHandler",
"/debug/pprof/symbol": "SymbolHandler",
"/debug/pprof/trace": "TraceHandler",
"/debug/pprof/mutex": "MutexHandler",
}
for _, router := range routers {
//fmt.Println(router.Path, router.Method, router.Handler)
name, ok := expectedRouters[router.Path]
if !ok {
t.Errorf("missing router %s", router.Path)
}
if !strings.Contains(router.Handler, name) {
t.Errorf("handler for %s should contain %s, got %s", router.Path, name, router.Handler)
}
}
}
func TestWrap(t *testing.T) {
r := newServer()
Wrap(r)
checkRouters(r.Routes(), t)
}
func TestWrapGroup(t *testing.T) {
for _, prefix := range []string{"/debug", "/debug/", "/debug/pprof", "/debug/pprof/"} {
r := newServer()
g := r.Group(prefix)
WrapGroup(g)
checkRouters(r.Routes(), t)
}
}