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

Function TestURLHandler

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

Source from the content-addressed store, hash-verified

42}
43
44func TestURLHandler(t *testing.T) {
45 out := &bytes.Buffer{}
46 r := &http.Request{
47 URL: &url.URL{Path: "/path", RawQuery: "foo=bar"},
48 }
49 h := URLHandler("url")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
50 l := FromRequest(r)
51 l.Log().Msg("")
52 }))
53 h = NewHandler(zerolog.New(out))(h)
54 h.ServeHTTP(nil, r)
55 if want, got := `{"url":"/path?foo=bar"}`+"\n", decodeIfBinary(out); want != got {
56 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
57 }
58}
59
60func TestMethodHandler(t *testing.T) {
61 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected