actions / actions/starter-workflows

`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.

Open Beginner friendly
#3,436 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
12.1k
Forks
7.3k
PR merge metrics
No merged PRs in 30d

Description

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 https://github.com/github/gh-aw/pull/55891

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/timeutil/format_test.go and compare the existing TestFormatDuration table with FormatDurationMs and FormatDurationNs in format.go. Add table-driven coverage for the listed boundaries, guards, rounding, and compositions, using testify/assert while preserving the existing names. Run the timeutil tests to verify the expected strings.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing-qa
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.