MCPcopy
hub / github.com/caddyserver/caddy / TestServer_LogRequest

Function TestServer_LogRequest

modules/caddyhttp/server_test.go:51–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func 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
76func TestServer_LogRequest_WithTrace(t *testing.T) {
77 s := &Server{}

Callers

nothing calls this directly

Calls 6

logRequestMethod · 0.95
NewResponseRecorderFunction · 0.85
NewTestReplacerFunction · 0.85
testLoggerFunction · 0.85
WithValueMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected