MCPcopy Index your code
hub / github.com/coder/coder / TestRequestLogger_WriteLog

Function TestRequestLogger_WriteLog

coderd/httpmw/loggermw/logger_internal_test.go:25–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestRequestLogger_WriteLog(t *testing.T) {
26 t.Parallel()
27 ctx := context.Background()
28
29 sink := testutil.NewFakeSink(t)
30 logger := sink.Logger()
31 logCtx := NewRequestLogger(logger, "GET", time.Now())
32
33 // Add custom fields
34 logCtx.WithFields(
35 slog.F("custom_field", "custom_value"),
36 )
37
38 // Write log for 200 status
39 logCtx.WriteLog(ctx, http.StatusOK)
40
41 entries := sink.Entries()
42 require.Len(t, entries, 1, "log was written twice")
43
44 require.Equal(t, entries[0].Message, "GET")
45
46 require.Equal(t, entries[0].Fields[0].Value, "custom_value")
47
48 // Attempt to write again (should be skipped).
49 logCtx.WriteLog(ctx, http.StatusInternalServerError)
50
51 entries = sink.Entries()
52 require.Len(t, entries, 1, "log was written twice")
53}
54
55func TestLoggerMiddleware_SingleRequest(t *testing.T) {
56 t.Parallel()

Callers

nothing calls this directly

Calls 8

LoggerMethod · 0.95
WithFieldsMethod · 0.95
WriteLogMethod · 0.95
EntriesMethod · 0.95
NewFakeSinkFunction · 0.92
NewRequestLoggerFunction · 0.70
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected