(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func 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 | |
| 161 | func TestContextRenderErrorsOnNoRenderer(t *testing.T) { |
| 162 | e := New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…