From 5e40c1d49c21bf989e8d54dbd555086f06d4fb8a Mon Sep 17 00:00:00 2001 From: Vas N Date: Mon, 25 May 2020 14:47:06 +0100 Subject: [PATCH] DebugPrintRouteFunc() unit test (#2395) Co-authored-by: thinkerou --- debug_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/debug_test.go b/debug_test.go index d707b4bfe7..d8cd5d1acc 100644 --- a/debug_test.go +++ b/debug_test.go @@ -7,6 +7,7 @@ package gin import ( "bytes" "errors" + "fmt" "html/template" "io" "log" @@ -64,6 +65,18 @@ func TestDebugPrintRoutes(t *testing.T) { assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param --> (.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest \(2 handlers\)\n$`, re) } +func TestDebugPrintRouteFunc(t *testing.T) { + DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { + fmt.Fprintf(DefaultWriter, "[GIN-debug] %-6s %-40s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers) + } + re := captureOutput(t, func() { + SetMode(DebugMode) + debugPrintRoute("GET", "/path/to/route/:param1/:param2", HandlersChain{func(c *Context) {}, handlerNameTest}) + SetMode(TestMode) + }) + assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param1/:param2 --> (.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest \(2 handlers\)\n$`, re) +} + func TestDebugPrintLoadTemplate(t *testing.T) { re := captureOutput(t, func() { SetMode(DebugMode)