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

Function TestResponseHeaderHandler

hlog/hlog_test.go:256–274  ·  hlog/hlog_test.go::TestResponseHeaderHandler
(t *testing.T)

Source from the content-addressed store, hash-verified

254}
255
256func TestResponseHeaderHandler(t *testing.T) {
257 out := &bytes.Buffer{}
258 w := httptest.NewRecorder()
259 r := &http.Request{}
260 h := ResponseHeaderHandler("encoding", "Content-Encoding")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
261 w.Header().Set("Content-Encoding", `gzip`)
262 w.WriteHeader(http.StatusOK)
263 }))
264 h2 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
265 h.ServeHTTP(w, r)
266 l := FromRequest(r)
267 l.Log().Msg("")
268 })
269 h3 := NewHandler(zerolog.New(out))(h2)
270 h3.ServeHTTP(w, r)
271 if want, got := `{"encoding":"gzip"}`+"\n", decodeIfBinary(out); want != got {
272 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
273 }
274}
275
276func TestProtoHandler(t *testing.T) {
277 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
ResponseHeaderHandlerFunction · 0.85
FromRequestFunction · 0.85
NewHandlerFunction · 0.85
decodeIfBinaryFunction · 0.85
WriteHeaderMethod · 0.80
MsgMethod · 0.80
SetMethod · 0.65
LogMethod · 0.65

Tested by

no test coverage detected