mirror of https://github.com/gin-gonic/gin.git
Adds HandlerName()
This commit is contained in:
parent
1a7ab6e4d5
commit
95c08d5f84
|
@ -72,6 +72,10 @@ func (c *Context) Copy() *Context {
|
||||||
return &cp
|
return &cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) HandlerName() string {
|
||||||
|
return nameOfFunction(c.handlers.Last())
|
||||||
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/*********** FLOW CONTROL ***********/
|
/*********** FLOW CONTROL ***********/
|
||||||
/************************************/
|
/************************************/
|
||||||
|
|
|
@ -135,6 +135,17 @@ func TestContextCopy(t *testing.T) {
|
||||||
assert.Equal(t, cp.Params, c.Params)
|
assert.Equal(t, cp.Params, c.Params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
func handlerNameTest(c *Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextQuery(t *testing.T) {
|
func TestContextQuery(t *testing.T) {
|
||||||
c, _, _ := createTestContext()
|
c, _, _ := createTestContext()
|
||||||
c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10", nil)
|
c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10", nil)
|
||||||
|
|
|
@ -40,7 +40,6 @@ func testRouteOK(method string, t *testing.T) {
|
||||||
|
|
||||||
performRequest(r, method, "/test2")
|
performRequest(r, method, "/test2")
|
||||||
assert.True(t, passedAny)
|
assert.True(t, passedAny)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSingleRouteOK tests that POST route is correctly invoked.
|
// TestSingleRouteOK tests that POST route is correctly invoked.
|
||||||
|
|
Loading…
Reference in New Issue