MCPcopy
hub / github.com/gin-gonic/gin / TestContextBindWithJSON

Function TestContextBindWithJSON

context_test.go:2154–2169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2152}
2153
2154func TestContextBindWithJSON(t *testing.T) {
2155 w := httptest.NewRecorder()
2156 c, _ := CreateTestContext(w)
2157
2158 c.Request, _ = http.NewRequest(http.MethodPost, "/", strings.NewReader(`{"foo":"bar", "bar":"foo"}`))
2159 c.Request.Header.Add("Content-Type", MIMEXML) // set fake content-type
2160
2161 var obj struct {
2162 Foo string `json:"foo"`
2163 Bar string `json:"bar"`
2164 }
2165 require.NoError(t, c.BindJSON(&obj))
2166 assert.Equal(t, "foo", obj.Bar)
2167 assert.Equal(t, "bar", obj.Foo)
2168 assert.Equal(t, 0, w.Body.Len())
2169}
2170
2171func TestContextBindWithXML(t *testing.T) {
2172 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 2

CreateTestContextFunction · 0.85
BindJSONMethod · 0.80

Tested by

no test coverage detected