(t *testing.T)
| 467 | } |
| 468 | |
| 469 | func 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()) |
nothing calls this directly
no test coverage detected