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

Function Test_Parser_Request_Body

client/hooks_test.go:469–636  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

467}
468
469func Test_Parser_Request_Body(t *testing.T) {
470 t.Parallel()
471
472 t.Run("json body", func(t *testing.T) {
473 t.Parallel()
474 type jsonData struct {
475 Name string `json:"name"`
476 }
477 client := New()
478 req := AcquireRequest().
479 SetJSON(jsonData{
480 Name: "foo",
481 })
482
483 err := parserRequestBody(client, req)
484 require.NoError(t, err)
485 require.Equal(t, []byte("{\"name\":\"foo\"}"), req.RawRequest.Body()) //nolint:testifylint // test
486 })
487
488 t.Run("xml body", func(t *testing.T) {
489 t.Parallel()
490 type xmlData struct {
491 XMLName xml.Name `xml:"body"`
492 Name string `xml:"name"`
493 }
494 client := New()
495 req := AcquireRequest().
496 SetXML(xmlData{
497 Name: "foo",
498 })
499
500 err := parserRequestBody(client, req)
501 require.NoError(t, err)
502 require.Equal(t, []byte("<body><name>foo</name></body>"), req.RawRequest.Body())
503 })
504
505 t.Run("CBOR body", func(t *testing.T) {
506 t.Parallel()
507 type cborData struct {
508 Name string `cbor:"name"`
509 Age int `cbor:"age"`
510 }
511
512 data := cborData{
513 Name: "foo",
514 Age: 12,
515 }
516
517 client := New()
518 req := AcquireRequest().
519 SetCBOR(data)
520
521 err := parserRequestBody(client, req)
522 require.NoError(t, err)
523
524 encoded, err := cbor.Marshal(data)
525 require.NoError(t, err)
526 require.Equal(t, encoded, req.RawRequest.Body())

Callers

nothing calls this directly

Calls 15

AcquireRequestFunction · 0.85
parserRequestBodyFunction · 0.85
AcquireFileFunction · 0.85
SetFileReaderFunction · 0.85
SetFormDataWithMapMethod · 0.80
AddFileWithReaderMethod · 0.80
ContainsMethod · 0.80
AddFileMethod · 0.80
AddFilesMethod · 0.80
SetFormDataMethod · 0.80
SetRawBodyMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected