MCPcopy
hub / github.com/redpanda-data/console / TestLoggerMethods

Function TestLoggerMethods

backend/pkg/logger/logger_test.go:62–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestLoggerMethods(t *testing.T) {
63 tests := []struct {
64 name string
65 logFunc func(*slog.Logger, context.Context, string, ...any)
66 level string
67 expected string
68 }{
69 {
70 name: "debug",
71 logFunc: (*slog.Logger).DebugContext,
72 level: "debug",
73 expected: "DEBUG",
74 },
75 {
76 name: "info",
77 logFunc: (*slog.Logger).InfoContext,
78 level: "info",
79 expected: "INFO",
80 },
81 {
82 name: "warn",
83 logFunc: (*slog.Logger).WarnContext,
84 level: "warn",
85 expected: "WARN",
86 },
87 {
88 name: "error",
89 logFunc: (*slog.Logger).ErrorContext,
90 level: "error",
91 expected: "ERROR",
92 },
93 }
94
95 for _, tt := range tests {
96 t.Run(tt.name, func(t *testing.T) {
97 var buf bytes.Buffer
98 logger := NewSlogLogger(
99 WithOutput(&buf),
100 WithFormat(FormatJSON), // Explicitly use JSON mode for predictable output
101 WithLevel(slog.LevelDebug), // Set to debug to capture all levels
102 )
103
104 tt.logFunc(logger, t.Context(), "test message", slog.String("key", "value"))
105
106 output := buf.String()
107 assert.Contains(t, output, "test message")
108 assert.Contains(t, output, `"key":"value"`)
109 assert.Contains(t, output, tt.expected)
110 })
111 }
112}
113
114func TestWithLevel(t *testing.T) {
115 tests := []struct {

Callers

nothing calls this directly

Calls 5

NewSlogLoggerFunction · 0.85
WithOutputFunction · 0.85
WithFormatFunction · 0.85
WithLevelFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…