1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-22 20:06:21 +02:00
echo/engine/fasthttp/response_test.go
Vishal Rana f96f40b5e6 More coverage on engine/...
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-06-07 17:08:13 -07:00

42 lines
1.0 KiB
Go

package fasthttp
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/valyala/fasthttp"
"github.com/labstack/gommon/log"
)
func TestResponseWriteHeader(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
res.WriteHeader(http.StatusOK)
assert.True(t, res.Committed())
assert.Equal(t, http.StatusOK, res.Status())
}
func TestResponseWrite(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
res.Write([]byte("test"))
assert.Equal(t, int64(4), res.Size())
assert.Equal(t, "test", string(c.Response.Body()))
}
func TestResponseSetCookie(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
cookie := new(fasthttp.Cookie)
cookie.SetKey("name")
cookie.SetValue("Jon Snow")
res.SetCookie(&Cookie{cookie})
c.Response.Header.SetCookie(cookie)
ck := new(fasthttp.Cookie)
ck.SetKey("name")
assert.True(t, c.Response.Header.Cookie(ck))
assert.Equal(t, "Jon Snow", string(ck.Value()))
}