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

Disable debug mode warning for tests #3134

Open
sazzer opened this issue Apr 30, 2022 · 0 comments
Open

Disable debug mode warning for tests #3134

sazzer opened this issue Apr 30, 2022 · 0 comments

Comments

@sazzer
Copy link

sazzer commented Apr 30, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant