pkg/timeutil/format_test.go only exercised FormatDuration, leaving FormatDurationMs and FormatDurationNs — both non-trivial (rounding, zero/negative guard, minute+second composition) — covered solely by the thinner, doc-driven spec_test.go. The existing test also used manual comparison instead of the testify/assert style used elsewhere in the repo.
Test-only change; format.go is untouched.
Changes
TestFormatDurationMs (new) — boundaries 0, 999, 1000, 59999, 60000, multi-minute compositions (90000, 125000, 3_600_000), and negative input.
TestFormatDurationNs (new) — zero/negative guard (including large negative), rounding boundaries around half-second (499_999_999, 500_000_000, 1_499_999_999, 1_500_000_000), and multi-hour durations.
TestFormatDuration — swapped if/t.Errorf for assert.Equal; table and sub-case names unchanged.
Negative ms behavior
FormatDurationMs(-500) falls into the ms < 1000 branch and returns "-500ms". Asserted as-is rather than changed: the function is used for elapsed-time display where negatives shouldn't arise, and altering the guard is a behavior change beyond a test-quality fix. Flagging for reviewer input if the em-dash treatment used by FormatDurationNs is preferred here too.
{
name: "negative milliseconds",
ms: -500,
expected: "-500ms",
},
Note on spec_test.go
Left in place. It lives in the external timeutil_test package and is intentionally documentation-driven (each case cites a README spec section), so it serves a different purpose than the exhaustive internal tables. The issue's suggestion to consolidate would collapse that distinction — worth a separate discussion if the duplication proves to drift.
Originally posted by @Copilot in github/gh-aw#55891
pkg/timeutil/format_test.goonly exercisedFormatDuration, leavingFormatDurationMsandFormatDurationNs— both non-trivial (rounding, zero/negative guard, minute+second composition) — covered solely by the thinner, doc-drivenspec_test.go. The existing test also used manual comparison instead of thetestify/assertstyle used elsewhere in the repo.Test-only change;
format.gois untouched.Changes
TestFormatDurationMs(new) — boundaries0,999,1000,59999,60000, multi-minute compositions (90000,125000,3_600_000), and negative input.TestFormatDurationNs(new) — zero/negative guard (including large negative), rounding boundaries around half-second (499_999_999,500_000_000,1_499_999_999,1_500_000_000), and multi-hour durations.TestFormatDuration— swappedif/t.Errorfforassert.Equal; table and sub-case names unchanged.Negative
msbehaviorFormatDurationMs(-500)falls into thems < 1000branch and returns"-500ms". Asserted as-is rather than changed: the function is used for elapsed-time display where negatives shouldn't arise, and altering the guard is a behavior change beyond a test-quality fix. Flagging for reviewer input if the em-dash treatment used byFormatDurationNsis preferred here too.{ name: "negative milliseconds", ms: -500, expected: "-500ms", },Note on
spec_test.goLeft in place. It lives in the external
timeutil_testpackage and is intentionally documentation-driven (each case cites a README spec section), so it serves a different purpose than the exhaustive internal tables. The issue's suggestion to consolidate would collapse that distinction — worth a separate discussion if the duplication proves to drift.Originally posted by @Copilot in github/gh-aw#55891