(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func TestServer_LogRequest_WithTrace(t *testing.T) { |
| 77 | s := &Server{} |
| 78 | |
| 79 | extra := new(ExtraLogFields) |
| 80 | ctx := context.WithValue(context.Background(), ExtraLogFieldsCtxKey, extra) |
| 81 | extra.Add(zap.String("traceID", "1234567890abcdef")) |
| 82 | extra.Add(zap.String("spanID", "12345678")) |
| 83 | |
| 84 | req := httptest.NewRequest(http.MethodGet, "/", nil).WithContext(ctx) |
| 85 | rec := httptest.NewRecorder() |
| 86 | wrec := NewResponseRecorder(rec, nil, nil) |
| 87 | |
| 88 | duration := 50 * time.Millisecond |
| 89 | repl := NewTestReplacer(req) |
| 90 | bodyReader := &lengthReader{Source: req.Body} |
| 91 | shouldLogCredentials := false |
| 92 | |
| 93 | buf := bytes.Buffer{} |
| 94 | accLog := testLogger(buf.Write) |
| 95 | s.logRequest(accLog, req, wrec, &duration, repl, bodyReader, shouldLogCredentials) |
| 96 | |
| 97 | assert.JSONEq(t, `{ |
| 98 | "msg":"handled request", "level":"info", "bytes_read":0, |
| 99 | "duration":"50ms", "resp_headers": {}, "size":0, |
| 100 | "status":0, "user_id":"", |
| 101 | "traceID":"1234567890abcdef", |
| 102 | "spanID":"12345678" |
| 103 | }`, buf.String()) |
| 104 | } |
| 105 | |
| 106 | func BenchmarkServer_LogRequest(b *testing.B) { |
| 107 | s := &Server{} |
nothing calls this directly
no test coverage detected