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

Function TestRefererHandler

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

Source from the content-addressed store, hash-verified

173}
174
175func TestRefererHandler(t *testing.T) {
176 out := &bytes.Buffer{}
177 r := &http.Request{
178 Header: http.Header{
179 "Referer": []string{"http://foo.com/bar"},
180 },
181 }
182 h := RefererHandler("referer")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
183 l := FromRequest(r)
184 l.Log().Msg("")
185 }))
186 h = NewHandler(zerolog.New(out))(h)
187 h.ServeHTTP(nil, r)
188 if want, got := `{"referer":"http://foo.com/bar"}`+"\n", decodeIfBinary(out); want != got {
189 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
190 }
191}
192
193func TestRequestIDHandler(t *testing.T) {
194 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected