github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/ginx/ginpprof/pprof_test.go (about) 1 package ginpprof 2 3 import ( 4 "testing" 5 6 "github.com/gin-gonic/gin" 7 ) 8 9 func newServer() *gin.Engine { 10 r := gin.Default() 11 return r 12 } 13 14 func checkRouters(routers gin.RoutesInfo, t *testing.T) { 15 expectedRouters := map[string]string{ 16 "/debug/pprof/": "IndexHandler", 17 "/debug/pprof/heap": "HeapHandler", 18 "/debug/pprof/goroutine": "GoroutineHandler", 19 "/debug/pprof/allocs": "AllocsHandler", 20 "/debug/pprof/block": "BlockHandler", 21 "/debug/pprof/threadcreate": "ThreadCreateHandler", 22 "/debug/pprof/cmdline": "CmdlineHandler", 23 "/debug/pprof/profile": "ProfileHandler", 24 "/debug/pprof/symbol": "SymbolHandler", 25 "/debug/pprof/trace": "TraceHandler", 26 "/debug/pprof/mutex": "MutexHandler", 27 } 28 29 for _, router := range routers { 30 // fmt.Println(router.Path, router.Method, router.Handler) 31 _, ok := expectedRouters[router.Path] 32 if !ok { 33 t.Errorf("missing router %s", router.Path) 34 } 35 } 36 } 37 38 func TestWrap(t *testing.T) { 39 r := newServer() 40 Wrap(r) 41 checkRouters(r.Routes(), t) 42 } 43 44 func TestWrapGroup(t *testing.T) { 45 for _, prefix := range []string{"/debug", "/debug/", "/debug/pprof", "/debug/pprof/"} { 46 r := newServer() 47 g := r.Group(prefix) 48 WrapGroup(g) 49 checkRouters(r.Routes(), t) 50 } 51 }