(t *testing.T)
| 238 | } |
| 239 | |
| 240 | func TestWithFormat(t *testing.T) { |
| 241 | tests := []struct { |
| 242 | name string |
| 243 | format Format |
| 244 | message string |
| 245 | checkJSON bool |
| 246 | }{ |
| 247 | { |
| 248 | name: "explicit json format", |
| 249 | format: FormatJSON, |
| 250 | message: "test message", |
| 251 | checkJSON: true, |
| 252 | }, |
| 253 | { |
| 254 | name: "explicit text format", |
| 255 | format: FormatText, |
| 256 | message: "test message", |
| 257 | checkJSON: false, |
| 258 | }, |
| 259 | } |
| 260 | |
| 261 | for _, tt := range tests { |
| 262 | t.Run(tt.name, func(t *testing.T) { |
| 263 | var buf bytes.Buffer |
| 264 | logger := NewSlogLogger( |
| 265 | WithOutput(&buf), |
| 266 | WithFormat(tt.format), |
| 267 | ) |
| 268 | |
| 269 | logger.Info(tt.message, slog.String("key", "value")) |
| 270 | |
| 271 | output := buf.String() |
| 272 | require.NotEmpty(t, output) |
| 273 | assert.Contains(t, output, tt.message) |
| 274 | |
| 275 | if tt.checkJSON { |
| 276 | // JSON format should contain quotes around keys and values |
| 277 | assert.Contains(t, output, `"msg":"test message"`) |
| 278 | assert.Contains(t, output, `"key":"value"`) |
| 279 | } else { |
| 280 | // Text format should be more human-readable |
| 281 | assert.Contains(t, output, "test message") |
| 282 | assert.Contains(t, output, "key=value") |
| 283 | } |
| 284 | }) |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | func TestDefaultFormat(t *testing.T) { |
| 289 | // Test that the default logger uses JSON format |
nothing calls this directly
no test coverage detected
searching dependent graphs…