Skip to content
Myr

test(response_writer): add tests for Flush() with and without http.Flusher (#4699)

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

* test(response_writer): add tests for Flush() with and without http.Flusher * test(response_writer): drop stray comment and clarify Flush regression note - Remove orphaned doc comment left at the end of the file - Reword the issue #4460 reference to reflect the no-panic guard ---------

authored by MuaazTasawar · committed by GitHub · parent 4a3eb31 · Browse files · 1 file+27 added−4 removed
This commit

State

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

Trailers

  • Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Diff stats

1 file+27 added−4 removed

  • other:+27 added−4 removed

1 file+27 added−4 removed

modified:response_writer_test.go+27 added-4 removed
13 unmodified lines
14 "github.com/stretchr/testify/assert"15 "github.com/stretchr/testify/require"16)1718// TODO19// func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {20// func (w *responseWriter) CloseNotify() <-chan bool {21// func (w *responseWriter) Flush() {18// TestResponseWriterFlushWithFlusher verifies Flush() calls the underlying Flusher.19func TestResponseWriterFlushWithFlusher(t *testing.T) {20 testWriter := httptest.NewRecorder()21 writer := &responseWriter{ResponseWriter: testWriter}22 writer.Flush()23 assert.True(t, testWriter.Flushed)24}2526// TestResponseWriterFlushWithNonFlusher verifies Flush() is a no-op27// when the underlying ResponseWriter does not implement http.Flusher.28// Guards against the panic reported in https://github.com/gin-gonic/gin/issues/446029func TestResponseWriterFlushWithNonFlusher(t *testing.T) {30 nonFlusher := &nonFlusherWriter{header: http.Header{}}31 writer := &responseWriter{ResponseWriter: nonFlusher}32 require.NotPanics(t, func() {33 writer.Flush()34 })35}3637// nonFlusherWriter is a minimal http.ResponseWriter that does NOT implement http.Flusher.38type nonFlusherWriter struct {39 header http.Header40}4142func (w *nonFlusherWriter) Header() http.Header { return w.header }43func (w *nonFlusherWriter) Write(b []byte) (int, error) { return len(b), nil }44func (w *nonFlusherWriter) WriteHeader(code int) {}4546var (47 _ ResponseWriter = &responseWriter{}48 _ http.ResponseWriter = &responseWriter{}49 _ http.ResponseWriter = ResponseWriter(&responseWriter{})
294 unmodified lines