From febfd57e0cba430079cc9df0dbf0fa2a1cd05585 Mon Sep 17 00:00:00 2001 From: Tyson Maly Date: Mon, 21 Sep 2015 08:03:29 -0400 Subject: [PATCH] replaced hard coded test paths to make it easier for contributors to run tests --- context_test.go | 2 +- debug_test.go | 2 +- gin.go | 9 +++++++++ gin_test.go | 10 +++++----- utils_test.go | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/context_test.go b/context_test.go index efdba7b2..14b93208 100644 --- a/context_test.go +++ b/context_test.go @@ -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) { diff --git a/debug_test.go b/debug_test.go index 7a352e6e..5aa2e843 100644 --- a/debug_test.go +++ b/debug_test.go @@ -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) { diff --git a/gin.go b/gin.go index 3834d67e..3f017b37 100644 --- a/gin.go +++ b/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 diff --git a/gin_test.go b/gin_test.go index b3b0eb6b..165eb22a 100644 --- a/gin_test.go +++ b/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", }) } diff --git a/utils_test.go b/utils_test.go index 11a5b684..624ccf4b 100644 --- a/utils_test.go +++ b/utils_test.go @@ -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() {