Skip to content

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. #3436

Description

@nexoracontrol-ops

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.

  • Fixes #55840

Originally posted by @Copilot in github/gh-aw#55891

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions