New Render API

This commit is contained in:
Manu Mtz-Almeida
2015-05-18 15:45:24 +02:00
parent 3066c35754
commit 947b53d4a2
13 changed files with 190 additions and 229 deletions

View File

@ -215,7 +215,8 @@ func TestContextRenderString(t *testing.T) {
// with Content-Type set to text/html
func TestContextRenderHTMLString(t *testing.T) {
c, w, _ := createTestContext()
c.HTMLString(201, "<html>%s %d</html>", "string", 3)
c.Header("Content-Type", "text/html; charset=utf-8")
c.String(201, "<html>%s %d</html>", "string", 3)
assert.Equal(t, w.Code, 201)
assert.Equal(t, w.Body.String(), "<html>string 3</html>")
@ -233,6 +234,22 @@ func TestContextRenderData(t *testing.T) {
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/csv")
}
func TestContextHeaders(t *testing.T) {
c, _, _ := createTestContext()
c.Header("Content-Type", "text/plain")
c.Header("X-Custom", "value")
assert.Equal(t, c.Writer.Header().Get("Content-Type"), "text/plain")
assert.Equal(t, c.Writer.Header().Get("X-Custom"), "value")
c.Header("Content-Type", "text/html")
c.Header("X-Custom", "")
assert.Equal(t, c.Writer.Header().Get("Content-Type"), "text/html")
_, exist := c.Writer.Header()["X-Custom"]
assert.False(t, exist)
}
// TODO
func TestContextRenderRedirectWithRelativePath(t *testing.T) {
c, w, _ := createTestContext()