1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00
echo/response_test.go
Vishal Rana 9b6c392829 Better tests for response.go
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-05-29 16:50:46 -07:00

61 lines
906 B
Go

package echo
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponse(t *testing.T) {
w := httptest.NewRecorder()
r := NewResponse(w)
// SetWriter
r.SetWriter(w)
// Writer
assert.Equal(t, w, r.Writer())
// Header
assert.NotNil(t, r.Header())
// WriteHeader
r.WriteHeader(http.StatusOK)
assert.Equal(t, http.StatusOK, r.status)
// committed
assert.True(t, r.committed)
// Response already committed
r.WriteHeader(http.StatusOK)
// Status
r.status = http.StatusOK
assert.Equal(t, http.StatusOK, r.Status())
// Write
s := "echo"
_, err := r.Write([]byte(s))
assert.NoError(t, err)
// Flush
r.Flush()
// Size
assert.Equal(t, int64(len(s)), r.Size())
// Hijack
assert.Panics(t, func() {
r.Hijack()
})
// CloseNotify
assert.Panics(t, func() {
r.CloseNotify()
})
// reset
r.reset(httptest.NewRecorder())
}