test: add more tests (#1856)
This commit is contained in:
@@ -129,7 +129,18 @@ func TestWriteJsonTimeout(t *testing.T) {
|
||||
// only log it and ignore
|
||||
w := tracedResponseWriter{
|
||||
headers: make(map[string][]string),
|
||||
timeout: true,
|
||||
err: http.ErrHandlerTimeout,
|
||||
}
|
||||
msg := message{Name: "anyone"}
|
||||
WriteJson(&w, http.StatusOK, msg)
|
||||
assert.Equal(t, http.StatusOK, w.code)
|
||||
}
|
||||
|
||||
func TestWriteJsonError(t *testing.T) {
|
||||
// only log it and ignore
|
||||
w := tracedResponseWriter{
|
||||
headers: make(map[string][]string),
|
||||
err: errors.New("foo"),
|
||||
}
|
||||
msg := message{Name: "anyone"}
|
||||
WriteJson(&w, http.StatusOK, msg)
|
||||
@@ -162,8 +173,8 @@ type tracedResponseWriter struct {
|
||||
hasBody bool
|
||||
code int
|
||||
lessWritten bool
|
||||
timeout bool
|
||||
wroteHeader bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (w *tracedResponseWriter) Header() http.Header {
|
||||
@@ -171,8 +182,8 @@ func (w *tracedResponseWriter) Header() http.Header {
|
||||
}
|
||||
|
||||
func (w *tracedResponseWriter) Write(bytes []byte) (n int, err error) {
|
||||
if w.timeout {
|
||||
return 0, http.ErrHandlerTimeout
|
||||
if w.err != nil {
|
||||
return 0, w.err
|
||||
}
|
||||
|
||||
n, err = w.builder.Write(bytes)
|
||||
|
||||
Reference in New Issue
Block a user