forked from labstack/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
43 lines (35 loc) · 963 Bytes
/
response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package echo
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponse(t *testing.T) {
e := New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
res := &Response{echo: e, Writer: rec}
// Before
res.Before(func() {
c.Response().Header().Set(HeaderServer, "echo")
})
res.Write([]byte("test"))
assert.Equal(t, "echo", rec.Header().Get(HeaderServer))
}
func TestResponse_Write_FallsBackToDefaultStatus(t *testing.T) {
e := New()
rec := httptest.NewRecorder()
res := &Response{echo: e, Writer: rec}
res.Write([]byte("test"))
assert.Equal(t, http.StatusOK, rec.Code)
}
func TestResponse_Write_UsesSetResponseCode(t *testing.T) {
e := New()
rec := httptest.NewRecorder()
res := &Response{echo: e, Writer: rec}
res.Status = http.StatusBadRequest
res.Write([]byte("test"))
assert.Equal(t, http.StatusBadRequest, rec.Code)
}