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

Function TestContextBadAutoBind

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

Source from the content-addressed store, hash-verified

2286}
2287
2288func TestContextBadAutoBind(t *testing.T) {
2289 w := httptest.NewRecorder()
2290 c, _ := CreateTestContext(w)
2291
2292 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", strings.NewReader("\"foo\":\"bar\", \"bar\":\"foo\"}"))
2293 c.Request.Header.Add("Content-Type", MIMEJSON)
2294 var obj struct {
2295 Foo string `json:"foo"`
2296 Bar string `json:"bar"`
2297 }
2298
2299 assert.False(t, c.IsAborted())
2300 require.Error(t, c.Bind(&obj))
2301 c.Writer.WriteHeaderNow()
2302
2303 assert.Empty(t, obj.Bar)
2304 assert.Empty(t, obj.Foo)
2305 assert.Equal(t, http.StatusBadRequest, w.Code)
2306 assert.True(t, c.IsAborted())
2307}
2308
2309func TestContextAutoShouldBindJSON(t *testing.T) {
2310 c, _ := CreateTestContext(httptest.NewRecorder())

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
IsAbortedMethod · 0.80
BindMethod · 0.65
WriteHeaderNowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected