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 74e43ba
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 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,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)
}

0 comments on commit 74e43ba

Please sign in to comment.