MCPcopy
hub / github.com/rs/zerolog / TestCombinedHandlers

Function TestCombinedHandlers

hlog/hlog_test.go:308–323  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

306}
307
308func TestCombinedHandlers(t *testing.T) {
309 out := &bytes.Buffer{}
310 r := &http.Request{
311 Method: "POST",
312 URL: &url.URL{Path: "/path", RawQuery: "foo=bar"},
313 }
314 h := MethodHandler("method")(RequestHandler("request")(URLHandler("url")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
315 l := FromRequest(r)
316 l.Log().Msg("")
317 }))))
318 h = NewHandler(zerolog.New(out))(h)
319 h.ServeHTTP(nil, r)
320 if want, got := `{"method":"POST","request":"POST /path?foo=bar","url":"/path?foo=bar"}`+"\n", decodeIfBinary(out); want != got {
321 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
322 }
323}
324
325func BenchmarkHandlers(b *testing.B) {
326 r := &http.Request{

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
MethodHandlerFunction · 0.85
RequestHandlerFunction · 0.85
URLHandlerFunction · 0.85
FromRequestFunction · 0.85
NewHandlerFunction · 0.85
decodeIfBinaryFunction · 0.85
MsgMethod · 0.80
LogMethod · 0.65

Tested by

no test coverage detected