(t *testing.T)
| 191 | } |
| 192 | |
| 193 | func TestRequestIDHandler(t *testing.T) { |
| 194 | out := &bytes.Buffer{} |
| 195 | r := &http.Request{ |
| 196 | Header: http.Header{ |
| 197 | "Referer": []string{"http://foo.com/bar"}, |
| 198 | }, |
| 199 | } |
| 200 | h := RequestIDHandler("id", "Request-Id")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 201 | id, ok := IDFromRequest(r) |
| 202 | if !ok { |
| 203 | t.Fatal("Missing id in request") |
| 204 | } |
| 205 | if want, got := id.String(), w.Header().Get("Request-Id"); got != want { |
| 206 | t.Errorf("Invalid Request-Id header, got: %s, want: %s", got, want) |
| 207 | } |
| 208 | l := FromRequest(r) |
| 209 | l.Log().Msg("") |
| 210 | if want, got := fmt.Sprintf(`{"id":"%s"}`+"\n", id), decodeIfBinary(out); want != got { |
| 211 | t.Errorf("Invalid log output, got: %s, want: %s", got, want) |
| 212 | } |
| 213 | })) |
| 214 | h = NewHandler(zerolog.New(out))(h) |
| 215 | h.ServeHTTP(httptest.NewRecorder(), r) |
| 216 | } |
| 217 | |
| 218 | func TestCustomHeaderHandler(t *testing.T) { |
| 219 | out := &bytes.Buffer{} |
nothing calls this directly
no test coverage detected