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

Function TestRenderJSON

render/render_test.go:26–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestRenderJSON(t *testing.T) {
27 w := httptest.NewRecorder()
28 data := map[string]any{
29 "foo": "bar",
30 "html": "<b>",
31 }
32
33 (JSON{data}).WriteContentType(w)
34 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
35
36 err := (JSON{data}).Render(w)
37
38 require.NoError(t, err)
39 assert.JSONEq(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", w.Body.String())
40 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
41}
42
43func TestRenderJSONError(t *testing.T) {
44 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 5

WriteContentTypeMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…