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

Function TestRequestHandler

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

Source from the content-addressed store, hash-verified

74}
75
76func TestRequestHandler(t *testing.T) {
77 out := &bytes.Buffer{}
78 r := &http.Request{
79 Method: "POST",
80 URL: &url.URL{Path: "/path", RawQuery: "foo=bar"},
81 }
82 h := RequestHandler("request")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
83 l := FromRequest(r)
84 l.Log().Msg("")
85 }))
86 h = NewHandler(zerolog.New(out))(h)
87 h.ServeHTTP(nil, r)
88 if want, got := `{"request":"POST /path?foo=bar"}`+"\n", decodeIfBinary(out); want != got {
89 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
90 }
91}
92
93func TestRemoteAddrHandler(t *testing.T) {
94 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected