TestContextShouldBindBodyWithYAML() — gin Function Reference
Architecture documentation for the TestContextShouldBindBodyWithYAML() function in context_test.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD 86e30019_da87_e529_05c3_d4c9a97eb260["TestContextShouldBindBodyWithYAML()"] ebe0ae48_a62b_a38f_5bac_5bbbd96fc508["context_test.go"] 86e30019_da87_e529_05c3_d4c9a97eb260 -->|defined in| ebe0ae48_a62b_a38f_5bac_5bbbd96fc508 style 86e30019_da87_e529_05c3_d4c9a97eb260 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
context_test.go lines 2687–2750
func TestContextShouldBindBodyWithYAML(t *testing.T) {
for _, tt := range []struct {
name string
bindingBody binding.BindingBody
body string
}{
{
name: " YAML & JSON-BODY ",
bindingBody: binding.JSON,
body: `{"foo":"FOO"}`,
},
{
name: " YAML & XML-BODY ",
bindingBody: binding.XML,
body: `<?xml version="1.0" encoding="UTF-8"?>
<root>
<foo>FOO</foo>
</root>`,
},
{
name: " YAML & YAML-BODY ",
bindingBody: binding.YAML,
body: `foo: FOO`,
},
{
name: " YAML & 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 typeYAML struct {
Foo string `yaml:"foo" binding:"required"`
}
objYAML := typeYAML{}
// YAML belongs to a super collection of JSON, so JSON can be parsed by YAML
if tt.bindingBody == binding.JSON {
require.NoError(t, c.ShouldBindBodyWithYAML(&objYAML))
assert.Equal(t, typeYAML{"FOO"}, objYAML)
}
if tt.bindingBody == binding.XML {
require.Error(t, c.ShouldBindBodyWithYAML(&objYAML))
assert.Equal(t, typeYAML{}, objYAML)
}
if tt.bindingBody == binding.YAML {
require.NoError(t, c.ShouldBindBodyWithYAML(&objYAML))
assert.Equal(t, typeYAML{"FOO"}, objYAML)
}
if tt.bindingBody == binding.TOML {
require.Error(t, c.ShouldBindBodyWithYAML(&objYAML))
assert.Equal(t, typeYAML{}, objYAML)
}
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does TestContextShouldBindBodyWithYAML() do?
TestContextShouldBindBodyWithYAML() is a function in the gin codebase, defined in context_test.go.
Where is TestContextShouldBindBodyWithYAML() defined?
TestContextShouldBindBodyWithYAML() is defined in context_test.go at line 2687.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free