Skip to content

Commit c7c613a

Browse files
committed
ensure a non-flushable response writer doesn't fail
1 parent 8e0ad88 commit c7c613a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

instrumentation/net/http/otelhttp/wrap_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,26 @@ func TestRespWriterFlush(t *testing.T) {
3535
assert.Equal(t, http.StatusOK, rw.statusCode)
3636
assert.True(t, rw.wroteHeader)
3737
}
38+
39+
type nonFlushableResponseWriter struct{}
40+
41+
func (_ nonFlushableResponseWriter) Header() http.Header {
42+
return http.Header{}
43+
}
44+
func (_ nonFlushableResponseWriter) Write([]byte) (int, error) {
45+
return 0, nil
46+
}
47+
48+
func (_ nonFlushableResponseWriter) WriteHeader(int) {}
49+
50+
func TestRespWriterFlushNoFlusher(t *testing.T) {
51+
52+
rw := &respWriterWrapper{
53+
ResponseWriter: nonFlushableResponseWriter{},
54+
record: func(int64) {},
55+
}
56+
57+
rw.Flush()
58+
assert.Equal(t, http.StatusOK, rw.statusCode)
59+
assert.True(t, rw.wroteHeader)
60+
}

0 commit comments

Comments
 (0)