2015-03-31 06:06:21 +02:00
|
|
|
package echo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
2015-05-30 01:50:46 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2015-03-31 06:06:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestResponse(t *testing.T) {
|
2015-05-30 01:50:46 +02:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
r := NewResponse(w)
|
|
|
|
|
|
|
|
// SetWriter
|
|
|
|
r.SetWriter(w)
|
|
|
|
|
|
|
|
// Writer
|
|
|
|
assert.Equal(t, w, r.Writer())
|
2015-03-31 06:06:21 +02:00
|
|
|
|
2015-04-19 01:47:48 +02:00
|
|
|
// Header
|
2015-05-30 01:50:46 +02:00
|
|
|
assert.NotNil(t, r.Header())
|
2015-03-31 06:06:21 +02:00
|
|
|
|
2015-04-19 01:47:48 +02:00
|
|
|
// WriteHeader
|
|
|
|
r.WriteHeader(http.StatusOK)
|
2015-05-30 01:50:46 +02:00
|
|
|
assert.Equal(t, http.StatusOK, r.status)
|
|
|
|
|
2015-05-30 19:54:55 +02:00
|
|
|
// Committed
|
2015-05-30 01:50:46 +02:00
|
|
|
assert.True(t, r.committed)
|
|
|
|
|
2015-05-30 19:54:55 +02:00
|
|
|
// Already committed
|
|
|
|
r.WriteHeader(http.StatusTeapot)
|
|
|
|
assert.NotEqual(t, http.StatusTeapot, r.Status())
|
2015-04-19 01:47:48 +02:00
|
|
|
|
|
|
|
// Status
|
|
|
|
r.status = http.StatusOK
|
2015-05-30 01:50:46 +02:00
|
|
|
assert.Equal(t, http.StatusOK, r.Status())
|
2015-04-19 01:47:48 +02:00
|
|
|
|
2015-05-30 01:50:46 +02:00
|
|
|
// Write
|
2015-04-19 01:47:48 +02:00
|
|
|
s := "echo"
|
2015-05-30 01:50:46 +02:00
|
|
|
_, err := r.Write([]byte(s))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Flush
|
|
|
|
r.Flush()
|
|
|
|
|
|
|
|
// Size
|
2015-05-30 19:54:55 +02:00
|
|
|
assert.Len(t, s, int(r.Size()))
|
2015-05-30 01:50:46 +02:00
|
|
|
|
|
|
|
// Hijack
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
r.Hijack()
|
|
|
|
})
|
|
|
|
|
|
|
|
// CloseNotify
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
r.CloseNotify()
|
|
|
|
})
|
2015-05-29 01:50:49 +02:00
|
|
|
|
|
|
|
// reset
|
2015-05-28 05:11:57 +02:00
|
|
|
r.reset(httptest.NewRecorder())
|
2015-03-31 06:06:21 +02:00
|
|
|
}
|