go test -run Test_Ctx_CustomCtx
(t *testing.T)
| 353 | |
| 354 | // go test -run Test_Ctx_CustomCtx |
| 355 | func Test_Ctx_CustomCtx(t *testing.T) { |
| 356 | t.Parallel() |
| 357 | |
| 358 | app := NewWithCustomCtx(func(app *App) CustomCtx { |
| 359 | return &customCtx{ |
| 360 | DefaultCtx: *NewDefaultCtx(app), |
| 361 | } |
| 362 | }) |
| 363 | |
| 364 | app.Get("/:id", func(c Ctx) error { |
| 365 | return c.SendString(c.Params("id")) |
| 366 | }) |
| 367 | resp, err := app.Test(httptest.NewRequest(MethodGet, "/v3", &bytes.Buffer{})) |
| 368 | require.NoError(t, err, "app.Test(req)") |
| 369 | defer func() { require.NoError(t, resp.Body.Close()) }() |
| 370 | |
| 371 | body, err := io.ReadAll(resp.Body) |
| 372 | require.NoError(t, err, "io.ReadAll(resp.Body)") |
| 373 | require.Len(t, body, len("prefix_v3")) |
| 374 | require.Equal(t, "prefix_v3", string(body)) |
| 375 | require.Equal(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType)) |
| 376 | require.Equal(t, int64(len(body)), resp.ContentLength) |
| 377 | } |
| 378 | |
| 379 | func Test_App_AcquireDefaultCtx_CustomCtxFallback(t *testing.T) { |
| 380 | t.Parallel() |
nothing calls this directly
no test coverage detected