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

Function TestContextNegotiationWithHTML

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

Source from the content-addressed store, hash-verified

1660}
1661
1662func TestContextNegotiationWithHTML(t *testing.T) {
1663 w := httptest.NewRecorder()
1664 c, router := CreateTestContext(w)
1665 c.Request, _ = http.NewRequest(http.MethodPost, "", nil)
1666 templ := template.Must(template.New("t").Parse(`Hello {{.name}}`))
1667 router.SetHTMLTemplate(templ)
1668
1669 c.Negotiate(http.StatusOK, Negotiate{
1670 Offered: []string{MIMEHTML},
1671 Data: H{"name": "gin"},
1672 HTMLName: "t",
1673 })
1674
1675 assert.Equal(t, http.StatusOK, w.Code)
1676 assert.Equal(t, "Hello gin", w.Body.String())
1677 assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type"))
1678}
1679
1680func TestContextNegotiationWithPROTOBUF(t *testing.T) {
1681 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected