summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/http/response_test.go24
-rw-r--r--static_pool.go2
2 files changed, 24 insertions, 2 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))
+}
diff --git a/static_pool.go b/static_pool.go
index f82bc797..665be234 100644
--- a/static_pool.go
+++ b/static_pool.go
@@ -270,4 +270,4 @@ func (p *StaticPool) throw(event int, ctx interface{}) {
if p.listener != nil {
p.listener(event, ctx)
}
-}
+} \ No newline at end of file