2015-03-31 06:06:21 +02:00
|
|
|
package echo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResponse(t *testing.T) {
|
2015-05-20 23:38:51 +02:00
|
|
|
r := NewResponse(httptest.NewRecorder())
|
2015-03-31 06:06:21 +02:00
|
|
|
|
2015-04-19 01:47:48 +02:00
|
|
|
// Header
|
|
|
|
if r.Header() == nil {
|
|
|
|
t.Error("header should not be nil")
|
|
|
|
}
|
2015-03-31 06:06:21 +02:00
|
|
|
|
2015-04-19 01:47:48 +02:00
|
|
|
// WriteHeader
|
|
|
|
r.WriteHeader(http.StatusOK)
|
|
|
|
if r.status != http.StatusOK {
|
|
|
|
t.Errorf("status should be %d", http.StatusOK)
|
|
|
|
}
|
|
|
|
if r.committed != true {
|
|
|
|
t.Error("response should be true")
|
|
|
|
}
|
|
|
|
// Response already committed
|
|
|
|
r.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
// Status
|
|
|
|
r.status = http.StatusOK
|
|
|
|
if r.Status() != http.StatusOK {
|
|
|
|
t.Errorf("status should be %d", http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write & Size
|
|
|
|
s := "echo"
|
|
|
|
r.Write([]byte(s))
|
2015-05-16 00:24:47 +02:00
|
|
|
if r.Size() != int64(len(s)) {
|
2015-04-19 01:47:48 +02:00
|
|
|
t.Errorf("size should be %d", len(s))
|
|
|
|
}
|
2015-05-28 05:11:57 +02:00
|
|
|
|
|
|
|
// reser
|
|
|
|
r.reset(httptest.NewRecorder())
|
|
|
|
if r.Size() != int64(0) {
|
|
|
|
t.Error("size should be 0")
|
|
|
|
}
|
2015-03-31 06:06:21 +02:00
|
|
|
}
|