From c7c613aea58b6f8016054ff25d5cec5b8b3f434c Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Wed, 22 May 2024 09:41:05 +0200 Subject: [PATCH] ensure a non-flushable response writer doesn't fail --- .../net/http/otelhttp/wrap_test.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/instrumentation/net/http/otelhttp/wrap_test.go b/instrumentation/net/http/otelhttp/wrap_test.go index 3fff3d1faf1..a35426e837e 100644 --- a/instrumentation/net/http/otelhttp/wrap_test.go +++ b/instrumentation/net/http/otelhttp/wrap_test.go @@ -35,3 +35,26 @@ 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) +}