(t *testing.T)
| 395 | } |
| 396 | |
| 397 | func TestError(t *testing.T) { |
| 398 | err1 := errors.Errorf("test error") |
| 399 | err2 := errors.Errorf("another error") |
| 400 | |
| 401 | var nilErr error |
| 402 | |
| 403 | tests := []struct { |
| 404 | name string |
| 405 | key string |
| 406 | value error |
| 407 | expected map[string]any |
| 408 | }{ |
| 409 | { |
| 410 | name: "simple error", |
| 411 | key: "err", |
| 412 | value: err1, |
| 413 | expected: map[string]any{ |
| 414 | "err": "test error", |
| 415 | }, |
| 416 | }, |
| 417 | { |
| 418 | name: "another error", |
| 419 | key: "error", |
| 420 | value: err2, |
| 421 | expected: map[string]any{ |
| 422 | "error": "another error", |
| 423 | }, |
| 424 | }, |
| 425 | { |
| 426 | name: "nil error", |
| 427 | key: "nil", |
| 428 | value: nilErr, |
| 429 | expected: map[string]any{ |
| 430 | "nil": nil, |
| 431 | }, |
| 432 | }, |
| 433 | } |
| 434 | |
| 435 | for _, tt := range tests { |
| 436 | t.Run(tt.name, func(t *testing.T) { |
| 437 | // Test memory allocations |
| 438 | allocs := testing.AllocsPerRun(100, func() { |
| 439 | _ = Error(tt.key, tt.value) |
| 440 | }) |
| 441 | require.Equal(t, float64(0), allocs, "Error() should not allocate memory") |
| 442 | |
| 443 | // Test output format |
| 444 | param := Error(tt.key, tt.value) |
| 445 | |
| 446 | jw := contentlog.NewJSONWriter() |
| 447 | defer jw.Release() |
| 448 | |
| 449 | jw.BeginObject() |
| 450 | param.WriteValueTo(jw) |
| 451 | jw.EndObject() |
| 452 | |
| 453 | var result map[string]any |
| 454 |
nothing calls this directly
no test coverage detected