forked from go-ozzo/ozzo-routing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_test.go
36 lines (29 loc) · 835 Bytes
/
writer_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
package routing
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDefaultDataWriter(t *testing.T) {
res := httptest.NewRecorder()
err := DefaultDataWriter.Write(res, "abc")
assert.Nil(t, err)
assert.Equal(t, "abc", res.Body.String())
res = httptest.NewRecorder()
err = DefaultDataWriter.Write(res, []byte("abc"))
assert.Nil(t, err)
assert.Equal(t, "abc", res.Body.String())
res = httptest.NewRecorder()
err = DefaultDataWriter.Write(res, 123)
assert.Nil(t, err)
assert.Equal(t, "123", res.Body.String())
res = httptest.NewRecorder()
err = DefaultDataWriter.Write(res, nil)
assert.Nil(t, err)
assert.Equal(t, "", res.Body.String())
res = httptest.NewRecorder()
c := &Context{}
c.init(res, nil)
assert.Nil(t, c.Write("abc"))
assert.Equal(t, "abc", res.Body.String())
}