|
|
@ -100,6 +100,18 @@ func TestWithinTimeout(t *testing.T) {
|
|
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestWithinTimeoutBadCode(t *testing.T) {
|
|
|
|
|
|
|
|
timeoutHandler := TimeoutHandler(time.Second)
|
|
|
|
|
|
|
|
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
|
|
|
|
|
|
|
|
resp := httptest.NewRecorder()
|
|
|
|
|
|
|
|
handler.ServeHTTP(resp, req)
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusInternalServerError, resp.Code)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestWithTimeoutTimedout(t *testing.T) {
|
|
|
|
func TestWithTimeoutTimedout(t *testing.T) {
|
|
|
|
timeoutHandler := TimeoutHandler(time.Millisecond)
|
|
|
|
timeoutHandler := TimeoutHandler(time.Millisecond)
|
|
|
|
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
@ -208,9 +220,7 @@ func TestTimeoutHijack(t *testing.T) {
|
|
|
|
resp := httptest.NewRecorder()
|
|
|
|
resp := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
|
|
writer := &timeoutWriter{
|
|
|
|
writer := &timeoutWriter{
|
|
|
|
w: &response.WithCodeResponseWriter{
|
|
|
|
w: response.NewWithCodeResponseWriter(resp),
|
|
|
|
Writer: resp,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
@ -218,9 +228,7 @@ func TestTimeoutHijack(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
writer = &timeoutWriter{
|
|
|
|
writer = &timeoutWriter{
|
|
|
|
w: &response.WithCodeResponseWriter{
|
|
|
|
w: response.NewWithCodeResponseWriter(mockedHijackable{resp}),
|
|
|
|
Writer: mockedHijackable{resp},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
@ -274,9 +282,7 @@ func TestTimeoutWriter_Hijack(t *testing.T) {
|
|
|
|
func TestTimeoutWroteTwice(t *testing.T) {
|
|
|
|
func TestTimeoutWroteTwice(t *testing.T) {
|
|
|
|
c := logtest.NewCollector(t)
|
|
|
|
c := logtest.NewCollector(t)
|
|
|
|
writer := &timeoutWriter{
|
|
|
|
writer := &timeoutWriter{
|
|
|
|
w: &response.WithCodeResponseWriter{
|
|
|
|
w: response.NewWithCodeResponseWriter(httptest.NewRecorder()),
|
|
|
|
Writer: httptest.NewRecorder(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
h: make(http.Header),
|
|
|
|
h: make(http.Header),
|
|
|
|
req: httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody),
|
|
|
|
req: httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody),
|
|
|
|
}
|
|
|
|
}
|
|
|
|