1 Star 0 Fork 0

只是条咸鱼罢了/ginpprof

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pprof_test.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
yuedf 提交于 2019-04-08 02:20 . support allocs in test
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)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/heytang/ginpprof.git
git@gitee.com:heytang/ginpprof.git
heytang
ginpprof
ginpprof
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385