mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 13:02:14 +08:00
replaced hard coded test paths to make it easier for contributors to run tests
This commit is contained in:
parent
704d690ac0
commit
febfd57e0c
@ -161,7 +161,7 @@ func TestContextHandlerName(t *testing.T) {
|
||||
c, _, _ := createTestContext()
|
||||
c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest}
|
||||
|
||||
assert.Equal(t, c.HandlerName(), "github.com/gin-gonic/gin.handlerNameTest")
|
||||
assert.Equal(t, c.HandlerName(), TestPath+"/gin.handlerNameTest")
|
||||
}
|
||||
|
||||
func handlerNameTest(c *Context) {
|
||||
|
@ -63,7 +63,7 @@ func TestDebugPrintRoutes(t *testing.T) {
|
||||
defer teardown()
|
||||
|
||||
debugPrintRoute("GET", "/path/to/route/:param", HandlersChain{func(c *Context) {}, handlerNameTest})
|
||||
assert.Equal(t, w.String(), "[GIN-debug] GET /path/to/route/:param --> github.com/gin-gonic/gin.handlerNameTest (2 handlers)\n")
|
||||
assert.Equal(t, w.String(), "[GIN-debug] GET /path/to/route/:param --> "+TestPath+"/gin.handlerNameTest (2 handlers)\n")
|
||||
}
|
||||
|
||||
func setup(w io.Writer) {
|
||||
|
9
gin.go
9
gin.go
@ -9,6 +9,8 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin/render"
|
||||
@ -20,6 +22,13 @@ const Version = "v1.0rc2"
|
||||
var default404Body = []byte("404 page not found")
|
||||
var default405Body = []byte("405 method not allowed")
|
||||
|
||||
// replace hardcoded paths in assertions within tests to
|
||||
// make it easier for contributors to run tests
|
||||
var _, CurrentFile, _, _ = runtime.Caller(1)
|
||||
var TestPath = path.Dir(path.Dir(path.Dir(CurrentFile)))
|
||||
|
||||
//TestPath,_ := os.Open(path.Join(path.Dir(TestFile), "gin.go"))
|
||||
|
||||
type HandlerFunc func(*Context)
|
||||
type HandlersChain []HandlerFunc
|
||||
|
||||
|
10
gin_test.go
10
gin_test.go
@ -217,27 +217,27 @@ func TestListOfRoutes(t *testing.T) {
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/favicon.ico",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test1",
|
||||
Handler: TestPath + "/gin.handler_test1",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test1",
|
||||
Handler: TestPath + "/gin.handler_test1",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/users/",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test2",
|
||||
Handler: TestPath + "/gin.handler_test2",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/users/:id",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test1",
|
||||
Handler: TestPath + "/gin.handler_test1",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
Method: "POST",
|
||||
Path: "/users/:id",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test2",
|
||||
Handler: TestPath + "/gin.handler_test2",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ func TestFilterFlags(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFunctionName(t *testing.T) {
|
||||
assert.Equal(t, nameOfFunction(somefunction), "github.com/gin-gonic/gin.somefunction")
|
||||
assert.Equal(t, nameOfFunction(somefunction), TestPath+"/gin.somefunction")
|
||||
}
|
||||
|
||||
func somefunction() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user