MCPcopy
hub / github.com/labstack/echo / TestContextRenderTemplateError

Function TestContextRenderTemplateError

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

Source from the content-addressed store, hash-verified

141}
142
143func TestContextRenderTemplateError(t *testing.T) {
144 // we test that when template rendering fails, no response is sent to the client yet, so the global error handler can decide what to do
145 e := New()
146 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userJSON))
147 rec := httptest.NewRecorder()
148 c := e.NewContext(req, rec)
149
150 tmpl := &Template{
151 templates: template.Must(template.New("hello").Parse("Hello, {{.}}!")),
152 }
153 c.Echo().Renderer = tmpl
154 err := c.Render(http.StatusOK, "not_existing", "Jon Snow")
155
156 assert.EqualError(t, err, `template: no template "not_existing" associated with template "hello"`)
157 assert.Equal(t, http.StatusOK, rec.Code) // status code must not be sent to the client
158 assert.Empty(t, rec.Body.String()) // body must not be sent to the client
159}
160
161func TestContextRenderErrorsOnNoRenderer(t *testing.T) {
162 e := New()

Callers

nothing calls this directly

Calls 5

EchoMethod · 0.95
RenderMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…