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

Function TestContextRenderHTML

context_test.go:1246–1258  ·  context_test.go::TestContextRenderHTML

Tests that the response executes the templates and responds with Content-Type set to text/html

(t *testing.T)

Source from the content-addressed store, hash-verified

1244// Tests that the response executes the templates
1245// and responds with Content-Type set to text/html
1246func TestContextRenderHTML(t *testing.T) {
1247 w := httptest.NewRecorder()
1248 c, router := CreateTestContext(w)
1249
1250 templ := template.Must(template.New("t").Parse(`Hello {{.name}}`))
1251 router.SetHTMLTemplate(templ)
1252
1253 c.HTML(http.StatusCreated, "t", H{"name": "alexandernyquist"})
1254
1255 assert.Equal(t, http.StatusCreated, w.Code)
1256 assert.Equal(t, "Hello alexandernyquist", w.Body.String())
1257 assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type"))
1258}
1259
1260func TestContextRenderHTML2(t *testing.T) {
1261 w := httptest.NewRecorder()

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