|
|
|
@ -79,6 +79,7 @@ func TestStdHandler(t *testing.T) {
|
|
|
|
|
name string
|
|
|
|
|
rh ReturnHandler
|
|
|
|
|
r *http.Request
|
|
|
|
|
errHandler ErrorHandlerFunc
|
|
|
|
|
wantCode int
|
|
|
|
|
wantLog AccessLogRecord
|
|
|
|
|
}{
|
|
|
|
@ -238,6 +239,26 @@ func TestStdHandler(t *testing.T) {
|
|
|
|
|
Code: 101,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "error handler gets run",
|
|
|
|
|
rh: handlerErr(0, Error(404, "not found", nil)), // status code changed in errHandler
|
|
|
|
|
r: req(bgCtx, "http://example.com/"),
|
|
|
|
|
wantCode: 200,
|
|
|
|
|
errHandler: func(w http.ResponseWriter, r *http.Request, e HTTPError) {
|
|
|
|
|
http.Error(w, e.Msg, 200)
|
|
|
|
|
},
|
|
|
|
|
wantLog: AccessLogRecord{
|
|
|
|
|
When: clock.Start,
|
|
|
|
|
Seconds: 1.0,
|
|
|
|
|
Proto: "HTTP/1.1",
|
|
|
|
|
TLS: false,
|
|
|
|
|
Host: "example.com",
|
|
|
|
|
Method: "GET",
|
|
|
|
|
Code: 404,
|
|
|
|
|
Err: "not found",
|
|
|
|
|
RequestURI: "/",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
@ -253,7 +274,7 @@ func TestStdHandler(t *testing.T) {
|
|
|
|
|
clock.Reset()
|
|
|
|
|
|
|
|
|
|
rec := noopHijacker{httptest.NewRecorder(), false}
|
|
|
|
|
h := StdHandler(test.rh, HandlerOptions{Logf: logf, Now: clock.Now})
|
|
|
|
|
h := StdHandler(test.rh, HandlerOptions{Logf: logf, Now: clock.Now, OnError: test.errHandler})
|
|
|
|
|
h.ServeHTTP(&rec, test.r)
|
|
|
|
|
res := rec.Result()
|
|
|
|
|
if res.StatusCode != test.wantCode {
|
|
|
|
|