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

Function TestFormatOverride

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

Source from the content-addressed store, hash-verified

303}
304
305func TestFormatOverride(t *testing.T) {
306 tests := []struct {
307 name string
308 format Format
309 expectedFormat string
310 description string
311 }{
312 {
313 name: "explicit JSON mode",
314 format: FormatJSON,
315 expectedFormat: "json",
316 description: "should use JSON format when explicitly set",
317 },
318 {
319 name: "explicit text mode",
320 format: FormatText,
321 expectedFormat: "text",
322 description: "should use text format when explicitly set",
323 },
324 }
325
326 for _, tt := range tests {
327 t.Run(tt.name, func(t *testing.T) {
328 var buf bytes.Buffer
329 logger := NewSlogLogger(
330 WithOutput(&buf),
331 WithFormat(tt.format),
332 )
333
334 logger.Info("test message", slog.String("key", "value"))
335
336 output := buf.String()
337 require.NotEmpty(t, output)
338
339 if tt.expectedFormat == "json" {
340 assert.Contains(t, output, `"msg":"test message"`)
341 assert.Contains(t, output, `"key":"value"`)
342 } else {
343 assert.Contains(t, output, "test message")
344 assert.Contains(t, output, "key=value")
345 }
346 })
347 }
348}
349
350func TestDurationFormatting(t *testing.T) {
351 tests := []struct {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…