Home / Function/ Test_Parser_Request_Body() — fiber Function Reference

Test_Parser_Request_Body() — fiber Function Reference

Architecture documentation for the Test_Parser_Request_Body() function in hooks_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  916abd0d_d8bf_a614_d3f5_42f60d79fd79["Test_Parser_Request_Body()"]
  9a0809c0_d0fc_f9e7_3fc4_bf20360f9ebf["hooks_test.go"]
  916abd0d_d8bf_a614_d3f5_42f60d79fd79 -->|defined in| 9a0809c0_d0fc_f9e7_3fc4_bf20360f9ebf
  style 916abd0d_d8bf_a614_d3f5_42f60d79fd79 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

client/hooks_test.go lines 469–636

func Test_Parser_Request_Body(t *testing.T) {
	t.Parallel()

	t.Run("json body", func(t *testing.T) {
		t.Parallel()
		type jsonData struct {
			Name string `json:"name"`
		}
		client := New()
		req := AcquireRequest().
			SetJSON(jsonData{
				Name: "foo",
			})

		err := parserRequestBody(client, req)
		require.NoError(t, err)
		require.Equal(t, []byte("{\"name\":\"foo\"}"), req.RawRequest.Body()) //nolint:testifylint // test
	})

	t.Run("xml body", func(t *testing.T) {
		t.Parallel()
		type xmlData struct {
			XMLName xml.Name `xml:"body"`
			Name    string   `xml:"name"`
		}
		client := New()
		req := AcquireRequest().
			SetXML(xmlData{
				Name: "foo",
			})

		err := parserRequestBody(client, req)
		require.NoError(t, err)
		require.Equal(t, []byte("<body><name>foo</name></body>"), req.RawRequest.Body())
	})

	t.Run("CBOR body", func(t *testing.T) {
		t.Parallel()
		type cborData struct {
			Name string `cbor:"name"`
			Age  int    `cbor:"age"`
		}

		data := cborData{
			Name: "foo",
			Age:  12,
		}

		client := New()
		req := AcquireRequest().
			SetCBOR(data)

		err := parserRequestBody(client, req)
		require.NoError(t, err)

		encoded, err := cbor.Marshal(data)
		require.NoError(t, err)
		require.Equal(t, encoded, req.RawRequest.Body())
	})

	t.Run("form data body", func(t *testing.T) {
		t.Parallel()
		client := New()
		req := AcquireRequest().
			SetFormDataWithMap(map[string]string{
				"ball": "circle and square",
			})

		err := parserRequestBody(client, req)
		require.NoError(t, err)
		require.Equal(t, "ball=circle+and+square", string(req.RawRequest.Body()))
	})

	t.Run("form data body error", func(t *testing.T) {
		t.Parallel()
		client := New()
		req := AcquireRequest().
			SetFormDataWithMap(map[string]string{
				"": "",
			})

Domain

Subdomains

Frequently Asked Questions

What does Test_Parser_Request_Body() do?
Test_Parser_Request_Body() is a function in the fiber codebase, defined in client/hooks_test.go.
Where is Test_Parser_Request_Body() defined?
Test_Parser_Request_Body() is defined in client/hooks_test.go at line 469.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free