mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 14:12:16 +08:00
Use regex for orgname in 'nameOf' methods
This commit is contained in:
parent
d1dbeb02cb
commit
9e8f29ea5a
@ -154,7 +154,7 @@ func TestContextHandlerName(t *testing.T) {
|
|||||||
c, _, _ := CreateTestContext()
|
c, _, _ := CreateTestContext()
|
||||||
c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest}
|
c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest}
|
||||||
|
|
||||||
assert.Regexp(t, "^(.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest$", c.HandlerName())
|
assert.Regexp(t, "^(.*/vendor/)?github.com/.*?/gin.handlerNameTest$", c.HandlerName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerNameTest(c *Context) {
|
func handlerNameTest(c *Context) {
|
||||||
|
@ -63,7 +63,7 @@ func TestDebugPrintRoutes(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
debugPrintRoute("GET", "/path/to/route/:param", HandlersChain{func(c *Context) {}, handlerNameTest})
|
debugPrintRoute("GET", "/path/to/route/:param", HandlersChain{func(c *Context) {}, handlerNameTest})
|
||||||
assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param --> (.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest \(2 handlers\)\n$`, w.String())
|
assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param --> (.*/vendor/)?github.com/.*?/gin.handlerNameTest \(2 handlers\)\n$`, w.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup(w io.Writer) {
|
func setup(w io.Writer) {
|
||||||
|
10
gin_test.go
10
gin_test.go
@ -217,27 +217,27 @@ func TestListOfRoutes(t *testing.T) {
|
|||||||
assertRoutePresent(t, list, RouteInfo{
|
assertRoutePresent(t, list, RouteInfo{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "/favicon.ico",
|
Path: "/favicon.ico",
|
||||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$",
|
Handler: "^(.*/vendor/)?github.com/.*?/gin.handlerTest1$",
|
||||||
})
|
})
|
||||||
assertRoutePresent(t, list, RouteInfo{
|
assertRoutePresent(t, list, RouteInfo{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$",
|
Handler: "^(.*/vendor/)?github.com/.*?/gin.handlerTest1$",
|
||||||
})
|
})
|
||||||
assertRoutePresent(t, list, RouteInfo{
|
assertRoutePresent(t, list, RouteInfo{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "/users/",
|
Path: "/users/",
|
||||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest2$",
|
Handler: "^(.*/vendor/)?github.com/.*?/gin.handlerTest2$",
|
||||||
})
|
})
|
||||||
assertRoutePresent(t, list, RouteInfo{
|
assertRoutePresent(t, list, RouteInfo{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "/users/:id",
|
Path: "/users/:id",
|
||||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$",
|
Handler: "^(.*/vendor/)?github.com/.*?/gin.handlerTest1$",
|
||||||
})
|
})
|
||||||
assertRoutePresent(t, list, RouteInfo{
|
assertRoutePresent(t, list, RouteInfo{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Path: "/users/:id",
|
Path: "/users/:id",
|
||||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest2$",
|
Handler: "^(.*/vendor/)?github.com/.*?/gin.handlerTest2$",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func TestFilterFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFunctionName(t *testing.T) {
|
func TestFunctionName(t *testing.T) {
|
||||||
assert.Regexp(t, `^(.*/vendor/)?github.com/gin-gonic/gin.somefunction$`, nameOfFunction(somefunction))
|
assert.Regexp(t, `^(.*/vendor/)?github.com/.*?/gin.somefunction$`, nameOfFunction(somefunction))
|
||||||
}
|
}
|
||||||
|
|
||||||
func somefunction() {
|
func somefunction() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user