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

Function TestUse

ginS/gins_test.go:151–168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestUse(t *testing.T) {
152 var middlewareExecuted bool
153 Use(func(c *gin.Context) {
154 middlewareExecuted = true
155 c.Next()
156 })
157
158 GET("/middleware-test", func(c *gin.Context) {
159 c.String(http.StatusOK, "ok")
160 })
161
162 req := httptest.NewRequest(http.MethodGet, "/middleware-test", nil)
163 w := httptest.NewRecorder()
164 engine().ServeHTTP(w, req)
165
166 assert.True(t, middlewareExecuted)
167 assert.Equal(t, http.StatusOK, w.Code)
168}
169
170func TestNoRoute(t *testing.T) {
171 NoRoute(func(c *gin.Context) {

Callers

nothing calls this directly

Calls 5

UseFunction · 0.85
GETFunction · 0.85
NextMethod · 0.80
StringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected