Skip to content
Myr

console logger HTTP status bug fixed and the corresponding unit test added (#3453)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alireza (Pure) · committed by GitHub · parent 82e1c53 · Browse files · 2 files+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−0 removed

  • other:+19 added−0 removed

2 files+19 added−0 removed

modified:response_writer_test.go+18 added
130 unmodified lines
131 resp, err := http.Get(testServer.URL)132 assert.NoError(t, err)133 assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)134}135136func TestResponseWriterStatusCode(t *testing.T) {137 testWriter := httptest.NewRecorder()138 writer := &responseWriter{}139 writer.reset(testWriter)140 w := ResponseWriter(writer)141142 w.WriteHeader(http.StatusOK)143 w.WriteHeaderNow()144145 assert.Equal(t, http.StatusOK, w.Status())146 assert.True(t, w.Written())147148 w.WriteHeader(http.StatusUnauthorized)149150 // status must be 200 although we tried to change it151 assert.Equal(t, http.StatusOK, w.Status())152}
modified:response_writer.go+1 added
59 unmodified lines
60func (w *responseWriter) WriteHeader(code int) {61 if code > 0 && w.status != code {62 if w.Written() {63 debugPrint("[WARNING] Headers were already written. Wanted to override status code %d with %d", w.status, code)64 return65 }66 w.status = code67 }68}
59 unmodified lines