go test -run Test_Ctx_RestartRoutingWithChangedPathAnd404
(t *testing.T)
| 8002 | |
| 8003 | // go test -run Test_Ctx_RestartRoutingWithChangedPathAnd404 |
| 8004 | func Test_Ctx_RestartRoutingWithChangedPathAndCatchAll(t *testing.T) { |
| 8005 | t.Parallel() |
| 8006 | app := New() |
| 8007 | app.Get("/new", func(_ Ctx) error { |
| 8008 | return nil |
| 8009 | }) |
| 8010 | app.Use(func(c Ctx) error { |
| 8011 | c.Path("/new") |
| 8012 | // c.Next() would fail this test as a 404 is returned from the next handler |
| 8013 | return c.RestartRouting() |
| 8014 | }) |
| 8015 | app.Use(func(_ Ctx) error { |
| 8016 | return ErrNotFound |
| 8017 | }) |
| 8018 | |
| 8019 | resp, err := app.Test(httptest.NewRequest(MethodGet, "http://example.com/old", http.NoBody)) |
| 8020 | require.NoError(t, err, "app.Test(req)") |
| 8021 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 8022 | } |
| 8023 | |
| 8024 | type testTemplateEngine struct { |
| 8025 | templates *template.Template |