| 587 | } |
| 588 | |
| 589 | func Test_Route_Match_Middleware(t *testing.T) { |
| 590 | t.Parallel() |
| 591 | |
| 592 | app := New() |
| 593 | |
| 594 | app.Use("/foo/*", func(c Ctx) error { |
| 595 | return c.SendString(c.Params("*")) |
| 596 | }) |
| 597 | |
| 598 | resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/*", http.NoBody)) |
| 599 | require.NoError(t, err, "app.Test(req)") |
| 600 | require.Equal(t, 200, resp.StatusCode, "Status code") |
| 601 | |
| 602 | body, err := io.ReadAll(resp.Body) |
| 603 | require.NoError(t, err, "app.Test(req)") |
| 604 | require.Equal(t, "*", app.toString(body)) |
| 605 | |
| 606 | // with param |
| 607 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/bar/fasel", http.NoBody)) |
| 608 | require.NoError(t, err, "app.Test(req)") |
| 609 | require.Equal(t, 200, resp.StatusCode, "Status code") |
| 610 | |
| 611 | body, err = io.ReadAll(resp.Body) |
| 612 | require.NoError(t, err, "app.Test(req)") |
| 613 | require.Equal(t, "bar/fasel", app.toString(body)) |
| 614 | } |
| 615 | |
| 616 | func Test_Route_Match_UnescapedPath(t *testing.T) { |
| 617 | t.Parallel() |