Skip to content

Expand test coverage for run loop, updater, and helpers#9

Merged
chenchaoyi merged 1 commit into
masterfrom
claude/expand-tests
Jun 23, 2026
Merged

Expand test coverage for run loop, updater, and helpers#9
chenchaoyi merged 1 commit into
masterfrom
claude/expand-tests

Conversation

@chenchaoyi

Copy link
Copy Markdown
Owner

Summary

Expands the test suite to cover the previously-untested core paths. Main-package statement coverage rises from ~52% → ~83% (cmd/testserver 0% → 50%; profile unchanged at ~82%).

What's now tested

  • run() — the full load loop end to end via a helper that resets flag.CommandLine and captures stdout/stderr:
    • happy-path JSON run, SLO pass (exit 0) and violation (exit 1)
    • -json-out to a file (success + unwritable → exit 3)
    • -version, every flag-validation branch (exit 2), missing profile / invalid proxy (exit 3), and the -stats-addr server path
  • Updater networkinggetRelease (success/404/500/bad-JSON/empty-tag), fetchLatestRelease + fetchReleaseByTag endpoints, downloadTo, and downloadWithFallback (primary success, mirror fallback, all-fail)
  • runUpdate-check (available / up to date), pinned -version, API error, -h, bad flag, and declining the confirmation prompt (via os.Stdin)
  • HelperswriteTempBinary read error, moveFile, color / isTTY / NO_COLOR / TERM=dumb, statusColor ranges, plain status & net-error breakdowns
  • cmd/testserverhello + helloJSON handlers

Production change

The hardcoded api.github.com / github.com hosts in update.go are now package vars (apiBaseURL / downloadBaseURL) so tests can point them at httptest servers. Production behavior is unchanged — they default to the real GitHub hosts.

Verification

go vet, gofmt -l, and go test -race ./... all clean.

🤖 Generated with Claude Code

Raise main-package coverage from ~52% to ~83% by exercising the parts that
were previously untested end to end:

- run(): happy-path JSON run, SLO pass/violation exit codes, -json-out file
  (success + unwritable), -version, every flag-validation branch, missing
  profile, invalid proxy, and the -stats-addr server path. Driven through a
  helper that resets flag.CommandLine and captures stdout/stderr.
- updater networking: getRelease (success/404/500/bad-JSON/empty-tag),
  fetchLatestRelease + fetchReleaseByTag endpoint paths, downloadTo, and
  downloadWithFallback (primary success, mirror fallback, all-fail).
- runUpdate: -check (update available / up to date), pinned -version,
  API-error exit, -h, bad flag, and declining the confirmation prompt.
- helpers: writeTempBinary read error, moveFile, color/TTY/NO_COLOR/dumb-term,
  statusColor ranges, and the plain status/net-error breakdowns.
- cmd/testserver: hello + helloJSON handlers.

To make the GitHub-backed paths testable without hitting the network, the
hardcoded api.github.com / github.com hosts in update.go are now package
vars (apiBaseURL/downloadBaseURL) that tests redirect at httptest servers;
production behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chenchaoyi chenchaoyi merged commit d177168 into master Jun 23, 2026
1 check passed
@chenchaoyi chenchaoyi deleted the claude/expand-tests branch June 23, 2026 16:04
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