Skip to content

tests: raise updater coverage from 68.8% to 86.6%#1

Merged
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage
May 27, 2026
Merged

tests: raise updater coverage from 68.8% to 86.6%#1
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

  • Adds two new *_test.go files (no production code modified)
  • Lifts package coverage from 68.8% → 86.6% (above the 85% target)
  • Closes branches in checkOnce, fetchLatestRelease, applyUpdate, downloadFile, VerifyChecksum, extractTarGz, replaceBinary, checkLoop, and the OS-dispatched signalDaemonRestart* helpers
  • Pins the security-critical "refuse install when checksums.txt is missing" + "fail if checksums download errors" paths (already had golden-path tests; this adds negative paths through applyUpdate, plus a corrupt-archive-with-valid-hash case)

Approach

  • All network mocked via httptest.NewServer — no calls to github.com
  • fetchLatestRelease hardcodes https://api.github.com/..., so tests inject an http.RoundTripper that rewrites scheme+host onto the test server. Lets us drive the full checkOnce path without modifying production code
  • Uses t.TempDir() everywhere; race detector clean

Coverage breakdown (after)

function before after
checkOnce 13.0% 100.0%
fetchLatestRelease 44.4% 94.4%
checkLoop 42.9% 92.9%
downloadFile 83.3% 100.0%
signalDaemonRestartLinux 0.0% 26.3%
applyUpdate 81.5% 88.9%
extractTarGz 86.2% 93.1%
VerifyChecksum 88.0% 96.0%
total 68.8% 86.6%

Test plan

  • go test -race -count=1 -timeout 120s ./... passes
  • go test -cover ./... reports >= 85%
  • No real network calls (httptest only)
  • No production code modified

Out of scope (iter-1 audit gaps, unchanged)

  • No Cosign/minisign binary signature verification yet (task #63)
  • No TLS pinning on api.github.com
  • These remain follow-up work; this PR just raises confidence in the existing checksum-only path

Add coverage-focused tests for previously uncovered branches:
- fetchLatestRelease: non-200, malformed JSON, transport error, UA injection
- checkOnce: fetch error, bad tag, missing daemon, up-to-date, apply error, full apply path
- applyUpdate: missing archive asset, archive download fail, checksum mismatch, corrupt archive
- downloadFile: non-200, unwritable dst, transport error, byte-cap sanity
- VerifyChecksum: missing checksums file, missing archive, blank lines + single-space separator
- replaceBinary: read-only dst dir, overwrite existing
- extractTarGz: read-only dest, truncated tar inside valid gzip
- checkLoop: ticker-fires-then-stop and stop-before-first-tick branches
- signalDaemonRestart{,Linux,Darwin}: smoke-test all three dispatchers
- archiveToInstall mapping pin

Tests use an http.RoundTripper rewriter to redirect the hardcoded
api.github.com URL onto httptest.NewServer — no real network calls.
No production code modified.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@TeoSlayer TeoSlayer merged commit 494d4af into main May 27, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 27, 2026 23:26
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.

2 participants