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

Function TestContextRenderNoContentHTML

context_test.go:1285–1296  ·  view source on GitHub ↗

Tests that no HTML is rendered if code is 204

(t *testing.T)

Source from the content-addressed store, hash-verified

1283
1284// Tests that no HTML is rendered if code is 204
1285func TestContextRenderNoContentHTML(t *testing.T) {
1286 w := httptest.NewRecorder()
1287 c, router := CreateTestContext(w)
1288 templ := template.Must(template.New("t").Parse(`Hello {{.name}}`))
1289 router.SetHTMLTemplate(templ)
1290
1291 c.HTML(http.StatusNoContent, "t", H{"name": "alexandernyquist"})
1292
1293 assert.Equal(t, http.StatusNoContent, w.Code)
1294 assert.Empty(t, w.Body.String())
1295 assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type"))
1296}
1297
1298// TestContextRenderXML tests that the response is serialized as XML
1299// and Content-Type is set to application/xml

Callers

nothing calls this directly

Calls 6

CreateTestContextFunction · 0.85
SetHTMLTemplateMethod · 0.80
HTMLMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected