MCPcopy
hub / github.com/gofiber/fiber / Test_NextCustom_MethodNotAllowed

Function Test_NextCustom_MethodNotAllowed

router_test.go:1955–1978  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1953}
1954
1955func Test_NextCustom_MethodNotAllowed(t *testing.T) {
1956 t.Parallel()
1957 app := newCustomApp()
1958 app.Get("/foo", func(c Ctx) error { return c.SendStatus(StatusOK) })
1959 useRoute := &Route{use: true, path: "/foo", Path: "/foo", routeParser: parseRoute("/foo", regexp.MustCompile)}
1960 m := app.methodInt(MethodGet)
1961 app.stack[m] = append([]*Route{useRoute}, app.stack[m]...)
1962 app.hasRoutesRefreshed = true
1963 app.ensureAutoHeadRoutes()
1964 app.RebuildTree()
1965
1966 fctx := &fasthttp.RequestCtx{}
1967 fctx.Request.Header.SetMethod(MethodPost)
1968 fctx.Request.SetRequestURI("/foo")
1969
1970 ctx := app.AcquireCtx(fctx)
1971 defer app.ReleaseCtx(ctx)
1972
1973 matched, err := app.nextCustom(ctx)
1974 require.False(t, matched)
1975 require.ErrorIs(t, err, ErrMethodNotAllowed)
1976 allow := string(ctx.Response().Header.Peek(HeaderAllow))
1977 require.Equal(t, "GET, HEAD", allow)
1978}
1979
1980func Test_NextCustom_SkipNonUseRoutesSkipsFallback(t *testing.T) {
1981 t.Parallel()

Callers

nothing calls this directly

Calls 12

newCustomAppFunction · 0.85
parseRouteFunction · 0.85
methodIntMethod · 0.80
ensureAutoHeadRoutesMethod · 0.80
RebuildTreeMethod · 0.80
SetMethodMethod · 0.80
AcquireCtxMethod · 0.80
ReleaseCtxMethod · 0.80
nextCustomMethod · 0.80
GetMethod · 0.65
SendStatusMethod · 0.65
ResponseMethod · 0.65

Tested by

no test coverage detected