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

Function TestContextRenderIndentedJSON

context_test.go:1141–1150  ·  view source on GitHub ↗

Tests that the response is serialized as JSON and Content-Type is set to application/json

(t *testing.T)

Source from the content-addressed store, hash-verified

1139// Tests that the response is serialized as JSON
1140// and Content-Type is set to application/json
1141func TestContextRenderIndentedJSON(t *testing.T) {
1142 w := httptest.NewRecorder()
1143 c, _ := CreateTestContext(w)
1144
1145 c.IndentedJSON(http.StatusCreated, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}})
1146
1147 assert.Equal(t, http.StatusCreated, w.Code)
1148 assert.JSONEq(t, "{\n \"bar\": \"foo\",\n \"foo\": \"bar\",\n \"nested\": {\n \"foo\": \"bar\"\n }\n}", w.Body.String())
1149 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
1150}
1151
1152// Tests that no Custom JSON is rendered if code is 204
1153func TestContextRenderNoContentIndentedJSON(t *testing.T) {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected