MCPcopy
hub / github.com/gofiber/fiber / Test_Response_Body

Function Test_Response_Body

client/response_test.go:308–453  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

306}
307
308func 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

Callers

nothing calls this directly

Calls 15

startTestServerFunction · 0.85
AcquireRequestFunction · 0.85
stopMethod · 0.80
dialMethod · 0.80
SetClientMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
SendStringMethod · 0.65
CBORMethod · 0.65
SetDialMethod · 0.65
BodyMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected