(t *testing.T)
| 518 | } |
| 519 | |
| 520 | func TestDuration(t *testing.T) { |
| 521 | tests := []struct { |
| 522 | name string |
| 523 | key string |
| 524 | value time.Duration |
| 525 | expected map[string]any |
| 526 | }{ |
| 527 | { |
| 528 | name: "positive duration", |
| 529 | key: "duration", |
| 530 | value: 5 * time.Second, |
| 531 | expected: map[string]any{ |
| 532 | "duration": 5000000.0, // microseconds |
| 533 | }, |
| 534 | }, |
| 535 | { |
| 536 | name: "negative duration", |
| 537 | key: "negative", |
| 538 | value: -2 * time.Minute, |
| 539 | expected: map[string]any{ |
| 540 | "negative": -120000000.0, // microseconds |
| 541 | }, |
| 542 | }, |
| 543 | { |
| 544 | name: "zero duration", |
| 545 | key: "zero", |
| 546 | value: 0, |
| 547 | expected: map[string]any{ |
| 548 | "zero": 0.0, |
| 549 | }, |
| 550 | }, |
| 551 | { |
| 552 | name: "microsecond duration", |
| 553 | key: "micro", |
| 554 | value: 123 * time.Microsecond, |
| 555 | expected: map[string]any{ |
| 556 | "micro": 123.0, |
| 557 | }, |
| 558 | }, |
| 559 | { |
| 560 | name: "nanosecond duration", |
| 561 | key: "nano", |
| 562 | value: 500 * time.Nanosecond, |
| 563 | expected: map[string]any{ |
| 564 | "nano": 0.0, // rounds down to microseconds |
| 565 | }, |
| 566 | }, |
| 567 | } |
| 568 | |
| 569 | for _, tt := range tests { |
| 570 | t.Run(tt.name, func(t *testing.T) { |
| 571 | // Test memory allocations |
| 572 | allocs := testing.AllocsPerRun(100, func() { |
| 573 | _ = Duration(tt.key, tt.value) |
| 574 | }) |
| 575 | require.Equal(t, float64(0), allocs, "Duration() should not allocate memory") |
| 576 | |
| 577 | // Test output format |
nothing calls this directly
no test coverage detected