-
Notifications
You must be signed in to change notification settings - Fork 57
/
pprof_test.go
77 lines (69 loc) · 2.17 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package echopprof
import (
"strings"
"testing"
"github.com/labstack/echo/v4"
)
func newServer() *echo.Echo {
e := echo.New()
return e
}
func checkRouters(routers []*echo.Route, t *testing.T, expectedRouters map[string]string) {
for _, router := range routers {
if (router.Method != "GET" && router.Method != "POST") || strings.HasSuffix(router.Path, "/*") {
continue
}
name, ok := expectedRouters[router.Path]
if !ok {
t.Errorf("missing router %s", router.Path)
}
if !strings.Contains(router.Name, name) {
t.Errorf("handler for %s should contain %s, got %s", router.Path, name, router.Name)
}
}
}
// go test github.com/sevenNt/echo-pprof -v -run=TestWrap\$
func TestWrap(t *testing.T) {
e := newServer()
Wrap(e)
expectedRouters := map[string]string{
"/debug/pprof": "IndexHandler",
"/debug/pprof/": "IndexHandler",
"/debug/pprof/heap": "HeapHandler",
"/debug/pprof/goroutine": "GoroutineHandler",
"/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",
}
checkRouters(e.Routes(), t, expectedRouters)
}
// go test github.com/sevenNt/echo-pprof -v -run=TestWrapGroup\$
func TestWrapGroup(t *testing.T) {
for _, prefix := range []string{"/debug"} {
e := newServer()
g := e.Group(prefix)
WrapGroup(prefix, g)
baseRouters := map[string]string{
"": "IndexHandler",
"/": "IndexHandler",
"/heap": "HeapHandler",
"/goroutine": "GoroutineHandler",
"/block": "BlockHandler",
"/threadcreate": "ThreadCreateHandler",
"/cmdline": "CmdlineHandler",
"/profile": "ProfileHandler",
"/symbol": "SymbolHandler",
"/trace": "TraceHandler",
"/mutex": "MutexHandler",
}
expectedRouters := make(map[string]string, len(baseRouters))
for r, h := range baseRouters {
expectedRouters[prefix+r] = h
}
checkRouters(e.Routes(), t, expectedRouters)
}
}