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

Function TestContextNegotiationWithJSON

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

Source from the content-addressed store, hash-verified

1600}
1601
1602func TestContextNegotiationWithJSON(t *testing.T) {
1603 w := httptest.NewRecorder()
1604 c, _ := CreateTestContext(w)
1605 c.Request, _ = http.NewRequest(http.MethodPost, "", nil)
1606
1607 c.Negotiate(http.StatusOK, Negotiate{
1608 Offered: []string{MIMEJSON, MIMEXML, MIMEYAML, MIMEYAML2},
1609 Data: H{"foo": "bar"},
1610 })
1611
1612 assert.Equal(t, http.StatusOK, w.Code)
1613 assert.JSONEq(t, `{"foo":"bar"}`, w.Body.String())
1614 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
1615}
1616
1617func TestContextNegotiationWithXML(t *testing.T) {
1618 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
NegotiateMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected