mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 01:57:55 +08:00
add tests when Context.reset() can be called inside of handler
TestEngineHandleContext TestContextResetInHandler TestRouterStaticFSFileNotFound
This commit is contained in:
parent
5c26a13482
commit
53263e4ba2
@ -1737,3 +1737,15 @@ func TestContextStreamWithClientGone(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, "test", w.Body.String())
|
assert.Equal(t, "test", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextResetInHandler(t *testing.T) {
|
||||||
|
w := CreateTestResponseRecorder()
|
||||||
|
c, _ := CreateTestContext(w)
|
||||||
|
|
||||||
|
c.handlers = []HandlerFunc{
|
||||||
|
func(c *Context) { c.reset() },
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
c.Next()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
17
gin_test.go
17
gin_test.go
@ -471,6 +471,23 @@ func TestListOfRoutes(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEngineHandleContext(t *testing.T) {
|
||||||
|
r := New()
|
||||||
|
r.GET("/", func(c *Context) {
|
||||||
|
c.Request.URL.Path = "/v2"
|
||||||
|
r.HandleContext(c)
|
||||||
|
})
|
||||||
|
v2 := r.Group("/v2")
|
||||||
|
{
|
||||||
|
v2.GET("/", func(c *Context) {})
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
w := performRequest(r, "GET", "/")
|
||||||
|
assert.Equal(t, 301, w.Code)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func assertRoutePresent(t *testing.T, gotRoutes RoutesInfo, wantRoute RouteInfo) {
|
func assertRoutePresent(t *testing.T, gotRoutes RoutesInfo, wantRoute RouteInfo) {
|
||||||
for _, gotRoute := range gotRoutes {
|
for _, gotRoute := range gotRoutes {
|
||||||
if gotRoute.Path == wantRoute.Path && gotRoute.Method == wantRoute.Method {
|
if gotRoute.Path == wantRoute.Path && gotRoute.Method == wantRoute.Method {
|
||||||
|
@ -426,6 +426,16 @@ func TestRouterStaticFSNotFound(t *testing.T) {
|
|||||||
assert.Equal(t, "non existent", w.Body.String())
|
assert.Equal(t, "non existent", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRouterStaticFSFileNotFound(t *testing.T) {
|
||||||
|
router := New()
|
||||||
|
|
||||||
|
router.StaticFS("/", http.FileSystem(http.Dir(".")))
|
||||||
|
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
performRequest(router, "GET", "/nonexistent")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestRouteRawPath(t *testing.T) {
|
func TestRouteRawPath(t *testing.T) {
|
||||||
route := New()
|
route := New()
|
||||||
route.UseRawPath = true
|
route.UseRawPath = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user