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

Function TestUserAgentHandler

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

Source from the content-addressed store, hash-verified

155}
156
157func TestUserAgentHandler(t *testing.T) {
158 out := &bytes.Buffer{}
159 r := &http.Request{
160 Header: http.Header{
161 "User-Agent": []string{"some user agent string"},
162 },
163 }
164 h := UserAgentHandler("ua")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
165 l := FromRequest(r)
166 l.Log().Msg("")
167 }))
168 h = NewHandler(zerolog.New(out))(h)
169 h.ServeHTTP(nil, r)
170 if want, got := `{"ua":"some user agent string"}`+"\n", decodeIfBinary(out); want != got {
171 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
172 }
173}
174
175func TestRefererHandler(t *testing.T) {
176 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected