Home / Function/ TestContextShouldBindBodyWithXML() — gin Function Reference

TestContextShouldBindBodyWithXML() — gin Function Reference

Architecture documentation for the TestContextShouldBindBodyWithXML() function in context_test.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  b8313240_a8b5_0c62_8e97_98726b2c0483["TestContextShouldBindBodyWithXML()"]
  ebe0ae48_a62b_a38f_5bac_5bbbd96fc508["context_test.go"]
  b8313240_a8b5_0c62_8e97_98726b2c0483 -->|defined in| ebe0ae48_a62b_a38f_5bac_5bbbd96fc508
  style b8313240_a8b5_0c62_8e97_98726b2c0483 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

context_test.go lines 2623–2685

func TestContextShouldBindBodyWithXML(t *testing.T) {
	for _, tt := range []struct {
		name        string
		bindingBody binding.BindingBody
		body        string
	}{
		{
			name:        " XML & JSON-BODY ",
			bindingBody: binding.JSON,
			body:        `{"foo":"FOO"}`,
		},
		{
			name:        " XML & XML-BODY ",
			bindingBody: binding.XML,
			body: `<?xml version="1.0" encoding="UTF-8"?>
<root>
<foo>FOO</foo>
</root>`,
		},
		{
			name:        " XML & YAML-BODY ",
			bindingBody: binding.YAML,
			body:        `foo: FOO`,
		},
		{
			name:        " XML & TOM-BODY ",
			bindingBody: binding.TOML,
			body:        `foo=FOO`,
		},
	} {
		t.Logf("testing: %s", tt.name)

		w := httptest.NewRecorder()
		c, _ := CreateTestContext(w)

		c.Request, _ = http.NewRequest(http.MethodPost, "/", bytes.NewBufferString(tt.body))

		type typeXML struct {
			Foo string `xml:"foo" binding:"required"`
		}
		objXML := typeXML{}

		if tt.bindingBody == binding.JSON {
			require.Error(t, c.ShouldBindBodyWithXML(&objXML))
			assert.Equal(t, typeXML{}, objXML)
		}

		if tt.bindingBody == binding.XML {
			require.NoError(t, c.ShouldBindBodyWithXML(&objXML))
			assert.Equal(t, typeXML{"FOO"}, objXML)
		}

		if tt.bindingBody == binding.YAML {
			require.Error(t, c.ShouldBindBodyWithXML(&objXML))
			assert.Equal(t, typeXML{}, objXML)
		}

		if tt.bindingBody == binding.TOML {
			require.Error(t, c.ShouldBindBodyWithXML(&objXML))
			assert.Equal(t, typeXML{}, objXML)
		}
	}
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does TestContextShouldBindBodyWithXML() do?
TestContextShouldBindBodyWithXML() is a function in the gin codebase, defined in context_test.go.
Where is TestContextShouldBindBodyWithXML() defined?
TestContextShouldBindBodyWithXML() is defined in context_test.go at line 2623.

Analyze Your Own Codebase

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

Try Supermodel Free