(t *testing.T)
| 306 | } |
| 307 | |
| 308 | func Test_Response_Body(t *testing.T) { |
| 309 | t.Parallel() |
| 310 | |
| 311 | setupApp := func() *testServer { |
| 312 | server := startTestServer(t, func(app *fiber.App) { |
| 313 | app.Get("/", func(c fiber.Ctx) error { |
| 314 | return c.SendString("hello world") |
| 315 | }) |
| 316 | |
| 317 | app.Get("/json", func(c fiber.Ctx) error { |
| 318 | return c.SendString("{\"status\":\"success\"}") |
| 319 | }) |
| 320 | |
| 321 | app.Get("/xml", func(c fiber.Ctx) error { |
| 322 | return c.SendString("<status><name>success</name></status>") |
| 323 | }) |
| 324 | |
| 325 | app.Get("/cbor", func(c fiber.Ctx) error { |
| 326 | type cborData struct { |
| 327 | Name string `cbor:"name"` |
| 328 | Age int `cbor:"age"` |
| 329 | } |
| 330 | |
| 331 | return c.CBOR(cborData{ |
| 332 | Name: "foo", |
| 333 | Age: 12, |
| 334 | }) |
| 335 | }) |
| 336 | }) |
| 337 | |
| 338 | return server |
| 339 | } |
| 340 | |
| 341 | t.Run("raw body", func(t *testing.T) { |
| 342 | t.Parallel() |
| 343 | |
| 344 | server := setupApp() |
| 345 | defer server.stop() |
| 346 | |
| 347 | client := New().SetDial(server.dial()) |
| 348 | |
| 349 | resp, err := AcquireRequest(). |
| 350 | SetClient(client). |
| 351 | Get("http://example.com") |
| 352 | |
| 353 | require.NoError(t, err) |
| 354 | require.Equal(t, []byte("hello world"), resp.Body()) |
| 355 | resp.Close() |
| 356 | }) |
| 357 | |
| 358 | t.Run("string body", func(t *testing.T) { |
| 359 | t.Parallel() |
| 360 | |
| 361 | server := setupApp() |
| 362 | defer server.stop() |
| 363 | |
| 364 | client := New().SetDial(server.dial()) |
| 365 |
nothing calls this directly
no test coverage detected