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

Function TestContextRenderTemplate

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

Source from the content-addressed store, hash-verified

123}
124
125func TestContextRenderTemplate(t *testing.T) {
126 e := New()
127 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userJSON))
128 rec := httptest.NewRecorder()
129
130 c := e.NewContext(req, rec)
131
132 tmpl := &Template{
133 templates: template.Must(template.New("hello").Parse("Hello, {{.}}!")),
134 }
135 c.Echo().Renderer = tmpl
136 err := c.Render(http.StatusOK, "hello", "Jon Snow")
137 if assert.NoError(t, err) {
138 assert.Equal(t, http.StatusOK, rec.Code)
139 assert.Equal(t, "Hello, Jon Snow!", rec.Body.String())
140 }
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

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…