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

Function TestMiddlewareAbort

middleware_test.go:159–183  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestMiddlewareAbort(t *testing.T) {
160 signature := ""
161 router := New()
162 router.Use(func(c *Context) {
163 signature += "A"
164 })
165 router.Use(func(c *Context) {
166 signature += "C"
167 c.AbortWithStatus(http.StatusUnauthorized)
168 c.Next()
169 signature += "D"
170 })
171 router.GET("/", func(c *Context) {
172 signature += " X "
173 c.Next()
174 signature += " XX "
175 })
176
177 // RUN
178 w := PerformRequest(router, http.MethodGet, "/")
179
180 // TEST
181 assert.Equal(t, http.StatusUnauthorized, w.Code)
182 assert.Equal(t, "ACD", signature)
183}
184
185func TestMiddlewareAbortHandlersChainAndNext(t *testing.T) {
186 signature := ""

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
PerformRequestFunction · 0.85
AbortWithStatusMethod · 0.80
NextMethod · 0.80
UseMethod · 0.65
GETMethod · 0.65

Tested by

no test coverage detected