MCPcopy
hub / github.com/gin-gonic/gin / TestEngineHandleContextPreventsMiddlewareReEntry

Function TestEngineHandleContextPreventsMiddlewareReEntry

gin_test.go:708–744  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

706}
707
708func TestEngineHandleContextPreventsMiddlewareReEntry(t *testing.T) {
709 // given
710 var handlerCounterV1, handlerCounterV2, middlewareCounterV1 int64
711
712 r := New()
713 v1 := r.Group("/v1")
714 {
715 v1.Use(func(c *Context) {
716 atomic.AddInt64(&middlewareCounterV1, 1)
717 })
718 v1.GET("/test", func(c *Context) {
719 atomic.AddInt64(&handlerCounterV1, 1)
720 c.Status(http.StatusOK)
721 })
722 }
723
724 v2 := r.Group("/v2")
725 {
726 v2.GET("/test", func(c *Context) {
727 c.Request.URL.Path = "/v1/test"
728 r.HandleContext(c)
729 }, func(c *Context) {
730 atomic.AddInt64(&handlerCounterV2, 1)
731 })
732 }
733
734 // when
735 responseV1 := PerformRequest(r, "GET", "/v1/test")
736 responseV2 := PerformRequest(r, "GET", "/v2/test")
737
738 // then
739 assert.Equal(t, 200, responseV1.Code)
740 assert.Equal(t, 200, responseV2.Code)
741 assert.Equal(t, int64(2), handlerCounterV1)
742 assert.Equal(t, int64(2), middlewareCounterV1)
743 assert.Equal(t, int64(1), handlerCounterV2)
744}
745
746func TestEngineHandleContextUseEscapedPathPercentEncoded(t *testing.T) {
747 r := New()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
PerformRequestFunction · 0.85
HandleContextMethod · 0.80
GroupMethod · 0.65
UseMethod · 0.65
GETMethod · 0.65
StatusMethod · 0.65

Tested by

no test coverage detected