Skip to content

tests: raise pilot-ca coverage from 60% to 90%#2

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

tests: raise pilot-ca coverage from 60% to 90%#2
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

  • Adds four new *_test.go files (no production code changes) lifting statement coverage from 60.4% → 90.6%.
  • Drives every branch of main() and die() (previously 0%) via a TestMain subprocess re-exec pattern.
  • Fills in the remaining error branches in loadRoot (84% → 100%) and verifyChain (80% → 95%).
  • All tests pass under go test -race -count=1 -timeout 120s ./....

Per-function coverage after

function before after
main 0.0% 100.0%
die 0.0% 100.0%
loadRoot 84.2% 100.0%
verifyChain 80.0% 95.0%
initRoot 80.0% 80.0%
issueBeacon 82.8% 82.8%
writePEM 85.7% 85.7%
randomSerial 80.0% 80.0%
mustMarshalPKCS8 100.0% 100.0%
total 60.4% 90.6%

The remaining uncovered branches are unreachable without injection (crypto/rand failures, pem.Encode write-to-closed-fd) and not worth the harness complexity.

Test plan

  • go test -race -count=1 -timeout 120s ./... passes locally
  • go test -cover reports >=85% (actual 90.6%)
  • No production code modified — only new zz_*_test.go files
  • All test state in t.TempDir(); ephemeral Ed25519/ECDSA keypairs only

Add four new *_test.go files (no production changes):

- zz_main_dispatch_test.go: subprocess re-exec via TestMain hijack
  drives every branch of main() and die() — usage, unknown subcommand,
  wrong arg counts, happy paths for init-root/issue-beacon/verify, and
  die-on-error paths for each. main() goes from 0% to 100%, die() from
  0% to 100%.

- zz_branches_test.go: fills in the remaining error branches in
  loadRoot (invalid key PEM, key PKCS8 parse failure, cert x509 parse
  failure) and verifyChain (missing leaf file, root PEM append failure,
  leaf x509 parse failure). loadRoot 84% to 100%, verifyChain 80% to 95%.

- zz_init_root_test.go, zz_load_test.go: small focused branch tests
  for initRoot/issueBeacon/loadRoot/writePEM/mustMarshalPKCS8 error
  paths that were previously uncovered.

All tests pass under -race -count=1 -timeout 120s and use t.TempDir()
with ephemeral keypairs — no real CA root touched.
@TeoSlayer TeoSlayer merged commit 705e7b8 into main May 27, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 27, 2026 23:26
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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