mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
29 lines
638 B
Go
29 lines
638 B
Go
|
package echo
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"html/template"
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestRenderWithTemplateRenderer(t *testing.T) {
|
||
|
e := New()
|
||
|
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userJSON))
|
||
|
rec := httptest.NewRecorder()
|
||
|
|
||
|
c := e.NewContext(req, rec)
|
||
|
|
||
|
e.Renderer = &TemplateRenderer{
|
||
|
Template: template.Must(template.New("hello").Parse("Hello, {{.}}!")),
|
||
|
}
|
||
|
|
||
|
err := c.Render(http.StatusOK, "hello", "Jon Snow")
|
||
|
if assert.NoError(t, err) {
|
||
|
assert.Equal(t, http.StatusOK, rec.Code)
|
||
|
assert.Equal(t, "Hello, Jon Snow!", rec.Body.String())
|
||
|
}
|
||
|
}
|