go test -run Test_Ctx_RestartRoutingWithChangedPath
(t *testing.T)
| 7976 | |
| 7977 | // go test -run Test_Ctx_RestartRoutingWithChangedPath |
| 7978 | func 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 |
| 8004 | func Test_Ctx_RestartRoutingWithChangedPathAndCatchAll(t *testing.T) { |
nothing calls this directly
no test coverage detected