(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func TestServer_LogRequest(t *testing.T) { |
| 52 | s := &Server{} |
| 53 | |
| 54 | ctx := context.Background() |
| 55 | ctx = context.WithValue(ctx, ExtraLogFieldsCtxKey, new(ExtraLogFields)) |
| 56 | req := httptest.NewRequest(http.MethodGet, "/", nil).WithContext(ctx) |
| 57 | rec := httptest.NewRecorder() |
| 58 | wrec := NewResponseRecorder(rec, nil, nil) |
| 59 | |
| 60 | duration := 50 * time.Millisecond |
| 61 | repl := NewTestReplacer(req) |
| 62 | bodyReader := &lengthReader{Source: req.Body} |
| 63 | shouldLogCredentials := false |
| 64 | |
| 65 | buf := bytes.Buffer{} |
| 66 | accLog := testLogger(buf.Write) |
| 67 | s.logRequest(accLog, req, wrec, &duration, repl, bodyReader, shouldLogCredentials) |
| 68 | |
| 69 | assert.JSONEq(t, `{ |
| 70 | "msg":"handled request", "level":"info", "bytes_read":0, |
| 71 | "duration":"50ms", "resp_headers": {}, "size":0, |
| 72 | "status":0, "user_id":"" |
| 73 | }`, buf.String()) |
| 74 | } |
| 75 | |
| 76 | func TestServer_LogRequest_WithTrace(t *testing.T) { |
| 77 | s := &Server{} |
nothing calls this directly
no test coverage detected