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

Function TestCustomHeaderHandler

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

Source from the content-addressed store, hash-verified

216}
217
218func TestCustomHeaderHandler(t *testing.T) {
219 out := &bytes.Buffer{}
220 r := &http.Request{
221 Header: http.Header{
222 "X-Request-Id": []string{"514bbe5bb5251c92bd07a9846f4a1ab6"},
223 },
224 }
225 h := CustomHeaderHandler("reqID", "X-Request-Id")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
226 l := FromRequest(r)
227 l.Log().Msg("")
228 }))
229 h = NewHandler(zerolog.New(out))(h)
230 h.ServeHTTP(nil, r)
231 if want, got := `{"reqID":"514bbe5bb5251c92bd07a9846f4a1ab6"}`+"\n", decodeIfBinary(out); want != got {
232 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
233 }
234}
235
236func TestEtagHandler(t *testing.T) {
237 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected