forked from sevennt/echo-pprof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pprof_test.go
58 lines (51 loc) · 1.49 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
package echopprof
import (
"strings"
"testing"
echo "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{
"/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",
}
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)
checkRouters(e.Routes(), t)
}
// 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)
checkRouters(e.Routes(), t)
}
}