Skip to content

test: cover TimeSpan rendering and wide day components - #479

Open
NickJosevski wants to merge 1 commit into
mainfrom
nj/timespan-test-coverage
Open

test: cover TimeSpan rendering and wide day components#479
NickJosevski wants to merge 1 commit into
mainfrom
nj/timespan-test-coverage

Conversation

@NickJosevski

Copy link
Copy Markdown
Contributor

Test-only. Salvages what is still useful from #435 / #452 after #458 fixed the underlying parser independently.

Why

#458 rewrote FromTimeSpan in both pkg/machines and pkg/machinepolicies and added tests, but those tests are thinner than the parser they guard:

  • ToTimeSpan is only exercised through the round trip. assert.Equal(t, d, FromTimeSpan(ToTimeSpan(d))) passes just as happily if both sides change together, so the wire format — the part the server actually reads — is unpinned. The day and fractional-second components are only rendered when non-zero, and none of that conditional formatting is asserted anywhere.
  • The day component is only covered at one and two digits. The server does not pad it, so it can be arbitrarily wide.
  • Field counts either side of three are unasserted. "not-a-timespan" is covered; "00:00" and "00:00:00:00" are not, and those are the shapes the len(parts) != 3 guard exists for.

What

Both copies of the test file get the same four additions, matching how the two packages are kept byte-identical:

added asserts
TestToTimeSpanRendersDotNetFormat eight exact rendered strings, covering both optional components present and absent
"37500.00:00:00" day component wider than two digits
"01.00:00:00.50000" day and fraction together, asserted directly rather than by subtracting 24h
"00:00", "00:00:00:00" too few and too many colon-separated fields

No production code changes — duration_formatter.go is untouched in both packages. All cases pass against main as it stands; they are regression protection, not a fix.

Attribution

The cases come from #435 by @Scott-Emberson, preserved as a co-author on the commit. His diagnosis of the day-component bug (#434) was correct and is what #458 went on to fix by another route; this keeps the coverage his PR would have added. #434, #435 and #452 are being closed against #458.

#458 fixed FromTimeSpan but left the tests thinner than the parser it
guards. ToTimeSpan was only exercised through the round trip, which cannot
tell a formatting change from a matching parsing change, so the optional
day and fractional-second components were unpinned in both directions.

Assert the rendered strings directly, and add the input shapes the parser
handles but nothing asserted: a day component wider than two digits, which
the server does not pad, a day and a fraction together, and colon-separated
field counts either side of three.

Cases taken from #435 by @Scott-Emberson, whose parser fix #458 landed
independently; these are the parts of that work still worth keeping.

Co-authored-by: Scott Emberson <8268155+Scott-Emberson@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant