Description
The official docs recommend testing by setting up a real router, which makes perfect sense.
However, this by default outputs the debug mode warning for every test. And this adds a load of clutter to the output.
I've just written a simple module (to support RFC-7807 problem responses) and have two tests for it. This has several lines of output per test just because of being in debug mode.
It might be that the answer is a new gin.NewTest()
method or similar that is used only for testing and that doesn't have this extra noise.
How to reproduce
package main_test
import (
"github.com/gin-gonic/gin"
"testing"
)
func TestSomething(t *testing.T) {
t.Parallel()
g := gin.Default()
}
func TestSomethingElse(t *testing.T) {
t.Parallel()
g := gin.Default()
}
Expectations
The test output should be clean of any unnecessary noise.
Actual result
=== RUN TestSomething
=== PAUSE TestSomething
=== RUN TestSomethingElse
=== PAUSE TestSomethingElse
=== CONT TestSomething
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
=== CONT TestSomethingElse
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
--- PASS: TestSomething (0.00s)
--- PASS: TestSomethingElse (0.00s)
PASS
Environment
- go version: 1.18.1
- gin version (or commit ref): v1.7.7
- operating system: macOS 12.3.1