go test -run Test_Ctx_CustomCtx
(t *testing.T)
| 442 | |
| 443 | // go test -run Test_Ctx_CustomCtx |
| 444 | func Test_Ctx_CustomCtx_and_Method(t *testing.T) { |
| 445 | t.Parallel() |
| 446 | |
| 447 | // Create app with custom request methods |
| 448 | methods := append(DefaultMethods, "JOHN") //nolint:gocritic // We want a new slice here |
| 449 | app := NewWithCustomCtx(func(app *App) CustomCtx { |
| 450 | return &customCtx{ |
| 451 | DefaultCtx: *NewDefaultCtx(app), |
| 452 | } |
| 453 | }, Config{ |
| 454 | RequestMethods: methods, |
| 455 | }) |
| 456 | |
| 457 | // Add route with custom method |
| 458 | app.Add([]string{"JOHN"}, "/doe", testEmptyHandler) |
| 459 | resp, err := app.Test(httptest.NewRequest("JOHN", "/doe", http.NoBody)) |
| 460 | require.NoError(t, err, "app.Test(req)") |
| 461 | defer func() { require.NoError(t, resp.Body.Close()) }() |
| 462 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 463 | |
| 464 | body, err := io.ReadAll(resp.Body) |
| 465 | require.NoError(t, err, "io.ReadAll(resp.Body)") |
| 466 | require.Empty(t, body) |
| 467 | require.Empty(t, resp.Header.Get(HeaderContentType)) |
| 468 | require.Equal(t, int64(0), resp.ContentLength) |
| 469 | |
| 470 | // Add a new method |
| 471 | require.Panics(t, func() { |
| 472 | app.Add([]string{"JANE"}, "/jane", testEmptyHandler) |
| 473 | }) |
| 474 | } |
| 475 | |
| 476 | // go test -run Test_Ctx_Accepts_EmptyAccept |
| 477 | func Test_Ctx_Accepts_EmptyAccept(t *testing.T) { |
nothing calls this directly
no test coverage detected