Skip to content

test_helpers.go should be named helpers_test.go #580

@tebeka

Description

@tebeka

test_helpers.go is built with the package. It should be built only when testing which means it should have the suffix _test.go. One side effect is that is that by test_helpers.go using httptest every program that uses gin gets -httptest.serve flag.

package main

import (
    "flag"
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    rtr := gin.Default()
    rtr.GET("/", func(ctx *gin.Context) {
        ctx.String(http.StatusOK, "Hi")
    })
    flag.Parse()
    rtr.Run(":8080")
}

Now run the program with --help and you'll see:

$ go run /tmp/t.go --help
[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)

[GIN-debug] GET    /                         --> main.main.func1 (3 handlers)
Usage of /tmp/go-build903640301/command-line-arguments/_obj/exe/t:
  -httptest.serve string
        if non-empty, httptest.NewServer serves on this address and blocks
exit status 2
$

Metadata

Metadata

Labels

type/bugFound something you weren't expecting? Report it here!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions