2016-06-06 01:17:01 +02:00
|
|
|
package standard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
2016-06-07 07:27:36 +02:00
|
|
|
|
|
|
|
"github.com/labstack/gommon/log"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-06-06 01:17:01 +02:00
|
|
|
)
|
|
|
|
|
2016-06-07 07:27:36 +02:00
|
|
|
func TestResponseWriteHeader(t *testing.T) {
|
2016-06-08 02:08:13 +02:00
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
res := NewResponse(rec, log.New("test"))
|
|
|
|
res.WriteHeader(http.StatusOK)
|
|
|
|
assert.True(t, res.Committed())
|
|
|
|
assert.Equal(t, http.StatusOK, res.Status())
|
2016-06-06 01:17:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 07:27:36 +02:00
|
|
|
func TestResponseWrite(t *testing.T) {
|
2016-06-08 02:08:13 +02:00
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
res := NewResponse(rec, log.New("test"))
|
|
|
|
res.Write([]byte("test"))
|
|
|
|
assert.Equal(t, int64(4), res.Size())
|
|
|
|
assert.Equal(t, "test", rec.Body.String())
|
|
|
|
res.Flush()
|
|
|
|
assert.True(t, rec.Flushed)
|
2016-06-06 01:17:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 07:27:36 +02:00
|
|
|
func TestResponseSetCookie(t *testing.T) {
|
2016-06-08 02:08:13 +02:00
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
res := NewResponse(rec, log.New("test"))
|
|
|
|
res.SetCookie(&Cookie{&http.Cookie{
|
|
|
|
Name: "name",
|
|
|
|
Value: "Jon Snow",
|
2016-06-06 01:17:01 +02:00
|
|
|
}})
|
2016-06-08 02:08:13 +02:00
|
|
|
assert.Equal(t, "name=Jon Snow", rec.Header().Get("Set-Cookie"))
|
2016-06-06 01:17:01 +02:00
|
|
|
}
|