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

Function TestContextAutoBindJSON

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

Source from the content-addressed store, hash-verified

2137}
2138
2139func TestContextAutoBindJSON(t *testing.T) {
2140 c, _ := CreateTestContext(httptest.NewRecorder())
2141 c.Request, _ = http.NewRequest(http.MethodPost, "/", strings.NewReader(`{"foo":"bar", "bar":"foo"}`))
2142 c.Request.Header.Add("Content-Type", MIMEJSON)
2143
2144 var obj struct {
2145 Foo string `json:"foo"`
2146 Bar string `json:"bar"`
2147 }
2148 require.NoError(t, c.Bind(&obj))
2149 assert.Equal(t, "foo", obj.Bar)
2150 assert.Equal(t, "bar", obj.Foo)
2151 assert.Empty(t, c.Errors)
2152}
2153
2154func TestContextBindWithJSON(t *testing.T) {
2155 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 2

CreateTestContextFunction · 0.85
BindMethod · 0.65

Tested by

no test coverage detected