forked from mirror/client_golang
Add test to expose interface upgrade bug
In principle, we needed to iterate through all permutations, mirroring the same that is happening in the code. For lack of time, I only picked one of the cases currently buggy. As said, this really needs code generation, should we ever find ourselves touching this again.
This commit is contained in:
parent
ebe4271dac
commit
d892fd2b51
|
@ -281,6 +281,16 @@ func (t *testResponseWriter) ReadFrom(io.Reader) (int64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// testFlusher is an http.ResponseWriter that also implements http.Flusher.
|
||||||
|
type testFlusher struct {
|
||||||
|
flushCalled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *testFlusher) Header() http.Header { return nil }
|
||||||
|
func (t *testFlusher) Write([]byte) (int, error) { return 0, nil }
|
||||||
|
func (t *testFlusher) WriteHeader(int) {}
|
||||||
|
func (t *testFlusher) Flush() { t.flushCalled = true }
|
||||||
|
|
||||||
func TestInterfaceUpgrade(t *testing.T) {
|
func TestInterfaceUpgrade(t *testing.T) {
|
||||||
w := &testResponseWriter{}
|
w := &testResponseWriter{}
|
||||||
d := newDelegator(w, nil)
|
d := newDelegator(w, nil)
|
||||||
|
@ -299,6 +309,22 @@ func TestInterfaceUpgrade(t *testing.T) {
|
||||||
if _, ok := d.(http.Hijacker); ok {
|
if _, ok := d.(http.Hijacker); ok {
|
||||||
t.Error("delegator unexpectedly implements http.Hijacker")
|
t.Error("delegator unexpectedly implements http.Hijacker")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f := &testFlusher{}
|
||||||
|
d = newDelegator(f, nil)
|
||||||
|
if _, ok := d.(http.CloseNotifier); ok {
|
||||||
|
t.Error("delegator unexpectedly implements http.CloseNotifier")
|
||||||
|
}
|
||||||
|
d.(http.Flusher).Flush()
|
||||||
|
if !w.flushCalled {
|
||||||
|
t.Error("Flush not called")
|
||||||
|
}
|
||||||
|
if _, ok := d.(io.ReaderFrom); ok {
|
||||||
|
t.Error("delegator unexpectedly implements io.ReaderFrom")
|
||||||
|
}
|
||||||
|
if _, ok := d.(http.Hijacker); ok {
|
||||||
|
t.Error("delegator unexpectedly implements http.Hijacker")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleInstrumentHandlerDuration() {
|
func ExampleInstrumentHandlerDuration() {
|
||||||
|
|
Loading…
Reference in New Issue