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

Function TestRouterMiddlewareAndStatic

routes_test.go:472–491  ·  routes_test.go::TestRouterMiddlewareAndStatic
(t *testing.T)

Source from the content-addressed store, hash-verified

470}
471
472func TestRouterMiddlewareAndStatic(t *testing.T) {
473 router := New()
474 static := router.Group("/", func(c *Context) {
475 c.Writer.Header().Add("Last-Modified", "Mon, 02 Jan 2006 15:04:05 MST")
476 c.Writer.Header().Add("Expires", "Mon, 02 Jan 2006 15:04:05 MST")
477 c.Writer.Header().Add("X-GIN", "Gin Framework")
478 })
479 static.Static("/", "./")
480
481 w := PerformRequest(router, http.MethodGet, "/gin.go")
482
483 assert.Equal(t, http.StatusOK, w.Code)
484 assert.Contains(t, w.Body.String(), "package gin")
485 // Content-Type='text/plain; charset=utf-8' when go version <= 1.16,
486 // else, Content-Type='text/x-go; charset=utf-8'
487 assert.NotEmpty(t, w.Header().Get("Content-Type"))
488 assert.NotEqual(t, "Mon, 02 Jan 2006 15:04:05 MST", w.Header().Get("Last-Modified"))
489 assert.Equal(t, "Mon, 02 Jan 2006 15:04:05 MST", w.Header().Get("Expires"))
490 assert.Equal(t, "Gin Framework", w.Header().Get("x-GIN"))
491}
492
493func TestRouteNotAllowedEnabled(t *testing.T) {
494 router := New()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
PerformRequestFunction · 0.85
GroupMethod · 0.65
StaticMethod · 0.65
StringMethod · 0.65
HeaderMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected