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

Function Test_Ctx_RestartRoutingWithChangedPath

ctx_test.go:7978–8001  ·  view source on GitHub ↗

go test -run Test_Ctx_RestartRoutingWithChangedPath

(t *testing.T)

Source from the content-addressed store, hash-verified

7976
7977// go test -run Test_Ctx_RestartRoutingWithChangedPath
7978func Test_Ctx_RestartRoutingWithChangedPath(t *testing.T) {
7979 t.Parallel()
7980 app := New()
7981 var executedOldHandler, executedNewHandler bool
7982
7983 app.Get("/old", func(c Ctx) error {
7984 c.Path("/new")
7985 return c.RestartRouting()
7986 })
7987 app.Get("/old", func(_ Ctx) error {
7988 executedOldHandler = true
7989 return nil
7990 })
7991 app.Get("/new", func(_ Ctx) error {
7992 executedNewHandler = true
7993 return nil
7994 })
7995
7996 resp, err := app.Test(httptest.NewRequest(MethodGet, "http://example.com/old", http.NoBody))
7997 require.NoError(t, err, "app.Test(req)")
7998 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
7999 require.False(t, executedOldHandler, "Executed old handler")
8000 require.True(t, executedNewHandler, "Executed new handler")
8001}
8002
8003// go test -run Test_Ctx_RestartRoutingWithChangedPathAnd404
8004func Test_Ctx_RestartRoutingWithChangedPathAndCatchAll(t *testing.T) {

Callers

nothing calls this directly

Calls 5

TestMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
PathMethod · 0.65
RestartRoutingMethod · 0.65

Tested by

no test coverage detected