Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TestWrapGroup #8

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/sevennt/echo-pprof
module github.com/sevenNt/echo-pprof

go 1.13

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/echo/v4 v4.1.11 h1:z0BZoArY4FqdpUEl+wlHp4hnr/oSR6MTmQmv8OHSoww=
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
Expand Down
49 changes: 33 additions & 16 deletions pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ func newServer() *echo.Echo {
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",
}

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
Expand All @@ -44,7 +31,21 @@ func checkRouters(routers []*echo.Route, t *testing.T) {
func TestWrap(t *testing.T) {
e := newServer()
Wrap(e)
checkRouters(e.Routes(), 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",
}

checkRouters(e.Routes(), t, expectedRouters)
}

// go test github.com/sevenNt/echo-pprof -v -run=TestWrapGroup\$
Expand All @@ -53,6 +54,22 @@ func TestWrapGroup(t *testing.T) {
e := newServer()
g := e.Group(prefix)
WrapGroup(prefix, g)
checkRouters(e.Routes(), t)
baseRouters := map[string]string{
"/": "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)
}
}