(t *testing.T)
| 303 | } |
| 304 | |
| 305 | func 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 | |
| 350 | func TestDurationFormatting(t *testing.T) { |
| 351 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…