|
9 | 9 | "errors"
|
10 | 10 | "fmt"
|
11 | 11 | "io"
|
| 12 | + "net/http" |
12 | 13 | "net/http/httptest"
|
13 | 14 | "os"
|
14 | 15 | "testing"
|
@@ -368,6 +369,33 @@ func Test_Router_NotFound_HTML_Inject(t *testing.T) {
|
368 | 369 | require.Equal(t, "Cannot DELETE /does/not/exist<script>alert('foo');</script>", string(c.Response.Body()))
|
369 | 370 | }
|
370 | 371 |
|
| 372 | +func Test_App_Rebuild_Tree(t *testing.T) { |
| 373 | + t.Parallel() |
| 374 | + app := New() |
| 375 | + |
| 376 | + app.Get("/test", func(c Ctx) error { |
| 377 | + app.Get("/dynamically-defined", func(c Ctx) error { |
| 378 | + return c.SendStatus(http.StatusOK) |
| 379 | + }) |
| 380 | + |
| 381 | + app.RebuildTree() |
| 382 | + |
| 383 | + return c.SendStatus(http.StatusOK) |
| 384 | + }) |
| 385 | + |
| 386 | + resp, err := app.Test(httptest.NewRequest(MethodGet, "/dynamically-defined", nil)) |
| 387 | + require.NoError(t, err, "app.Test(req)") |
| 388 | + require.Equal(t, http.StatusNotFound, resp.StatusCode, "Status code") |
| 389 | + |
| 390 | + resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil)) |
| 391 | + require.NoError(t, err, "app.Test(req)") |
| 392 | + require.Equal(t, http.StatusOK, resp.StatusCode, "Status code") |
| 393 | + |
| 394 | + resp, err = app.Test(httptest.NewRequest(MethodGet, "/dynamically-defined", nil)) |
| 395 | + require.NoError(t, err, "app.Test(req)") |
| 396 | + require.Equal(t, http.StatusOK, resp.StatusCode, "Status code") |
| 397 | +} |
| 398 | + |
371 | 399 | //////////////////////////////////////////////
|
372 | 400 | ///////////////// BENCHMARKS /////////////////
|
373 | 401 | //////////////////////////////////////////////
|
|
0 commit comments