replaced hard coded test paths to make it easier for contributors to run tests

This commit is contained in:
Tyson Maly 2015-09-21 08:03:29 -04:00
parent 704d690ac0
commit febfd57e0c
5 changed files with 17 additions and 8 deletions

View File

@ -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) {

View File

@ -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
View File

@ -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

View File

@ -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",
})
}

View File

@ -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() {