diff options
author | Wolfy-J <[email protected]> | 2018-06-11 22:13:27 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-11 22:13:27 +0300 |
commit | ec9cc7d1b90148c757ffab76e43d88798c20e5e0 (patch) | |
tree | 3d3eac4ae156f274fa696bbd2524c9ac7342df46 /service/http/response_test.go | |
parent | c8557f7cba16593ebc81f8d48d925f8e187fc4a2 (diff) |
coverage
Diffstat (limited to 'service/http/response_test.go')
-rw-r--r-- | service/http/response_test.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/service/http/response_test.go b/service/http/response_test.go index dfc08104..b8c98d66 100644 --- a/service/http/response_test.go +++ b/service/http/response_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "net/http" "bytes" + "github.com/pkg/errors" ) type testWriter struct { @@ -13,6 +14,7 @@ type testWriter struct { buf bytes.Buffer wroteHeader bool code int + err error } func (tw *testWriter) Header() http.Header { return tw.h } @@ -22,7 +24,12 @@ func (tw *testWriter) Write(p []byte) (int, error) { tw.WriteHeader(http.StatusOK) } - return tw.buf.Write(p) + n, e := tw.buf.Write(p) + if e == nil { + e = tw.err + } + + return n, e } func (tw *testWriter) WriteHeader(code int) { tw.wroteHeader = true; tw.code = code } @@ -68,3 +75,18 @@ func TestNewResponse_Stream(t *testing.T) { assert.Equal(t, "value", w.h.Get("key")) assert.Equal(t, "hello world", w.buf.String()) } + +func TestNewResponse_StreamError(t *testing.T) { + r, err := NewResponse(&roadrunner.Payload{ + Context: []byte(`{"headers":{"key":["value"]},"status": 301}`), + }) + + r.body = &bytes.Buffer{} + r.body.(*bytes.Buffer).WriteString("hello world") + + assert.NoError(t, err) + assert.NotNil(t, r) + + w := &testWriter{h: http.Header(make(map[string][]string)), err: errors.New("error")} + assert.Error(t, r.Write(w)) +} |