-
Notifications
You must be signed in to change notification settings - Fork 18
/
stat_handler_wrapper_1.7_test.go
80 lines (71 loc) · 1.44 KB
/
stat_handler_wrapper_1.7_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//go:build !go1.8
// +build !go1.8
package stats
import (
"fmt"
"net/http"
"testing"
)
func TestHTTPHandler_WrapResponse(t *testing.T) {
t.Parallel()
tests := []http.ResponseWriter{
struct {
http.ResponseWriter
http.Flusher
http.Hijacker
http.CloseNotifier
}{},
struct {
http.ResponseWriter
http.Flusher
http.Hijacker
}{},
struct {
http.ResponseWriter
http.Flusher
http.CloseNotifier
}{},
struct {
http.ResponseWriter
http.Flusher
}{},
struct {
http.ResponseWriter
http.Hijacker
http.CloseNotifier
}{},
struct {
http.ResponseWriter
http.Hijacker
}{},
struct {
http.ResponseWriter
http.CloseNotifier
}{},
struct {
http.ResponseWriter
}{},
}
h := NewStatHandler(
NewStore(NewNullSink(), false),
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})).(*httpHandler)
for i, test := range tests {
tc := test
t.Run(fmt.Sprint("test:", i), func(t *testing.T) {
t.Parallel()
_, canFlush := tc.(http.Flusher)
_, canHijack := tc.(http.Hijacker)
_, canNotify := tc.(http.CloseNotifier)
rw := h.wrapResponse(tc)
if _, ok := rw.(http.Flusher); ok != canFlush {
t.Errorf("Flusher: wanted %t", canFlush)
}
if _, ok := rw.(http.Hijacker); ok != canHijack {
t.Errorf("Hijacker: wanted %t", canHijack)
}
if _, ok := rw.(http.CloseNotifier); ok != canNotify {
t.Errorf("CloseNotifier: wanted %t", canNotify)
}
})
}
}