forked from open-telemetry/opentelemetry-go-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrap_test.go
60 lines (46 loc) · 1.3 KB
/
wrap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package otelhttp
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRespWriterWriteHeader(t *testing.T) {
rw := &respWriterWrapper{
ResponseWriter: &httptest.ResponseRecorder{},
record: func(int64) {},
}
rw.WriteHeader(http.StatusTeapot)
assert.Equal(t, http.StatusTeapot, rw.statusCode)
assert.True(t, rw.wroteHeader)
rw.WriteHeader(http.StatusGone)
assert.Equal(t, http.StatusTeapot, rw.statusCode)
}
func TestRespWriterFlush(t *testing.T) {
rw := &respWriterWrapper{
ResponseWriter: &httptest.ResponseRecorder{},
record: func(int64) {},
}
rw.Flush()
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)
}