Skip to content

Commit

Permalink
ensure a non-flushable response writer doesn't fail
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed May 22, 2024
1 parent 8e0ad88 commit 19edb3f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions instrumentation/net/http/otelhttp/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,25 @@ func TestRespWriterFlush(t *testing.T) {
assert.Equal(t, http.StatusOK, rw.statusCode)
assert.True(t, rw.wroteHeader)
}

type nonFlushableResponseWriter struct{}

func (_ nonFlushableResponseWriter) Header() http.Header {
return http.Header{}
}
func (_ nonFlushableResponseWriter) Write([]byte) (int, error) {
return 0, nil
}

func (_ nonFlushableResponseWriter) WriteHeader(int) {}

func TestRespWriterFlushNoFlusher(t *testing.T) {
rw := &respWriterWrapper{
ResponseWriter: nonFlushableResponseWriter{},
record: func(int64) {},
}

rw.Flush()
assert.Equal(t, http.StatusOK, rw.statusCode)
assert.True(t, rw.wroteHeader)
}

0 comments on commit 19edb3f

Please sign in to comment.