Skip to content

tests: push coverage to 98.2% with targeted unit + characterization tests#1

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

tests: push coverage to 98.2% with targeted unit + characterization tests#1
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

Lifts coverage from baseline 83.7% → 98.2% via a single new test file (zz_coverage_test.go, no production code changes).

What got covered

Area Before After
service.go (plugin adapter) 0% 100%
client.go (every method) 66–78% 100%
extractCallerNode 80% 100%
handleConn 76.9% 100%
ListenAndServe 90.9% 100%
handleRegister 90.9% 100%
reapExpired 50% 100%
records.go save/load 72.7% / 78.6% 81.8% / 96.4%
Total 83.7% 98.2%

Iter-2 audit follow-throughs

  • extractCallerNode silent-zero on plain pilot addr: pinned as a regression test. net.SplitHostPort treats the first colon in N:NNNN.HHHH.LLLL as host:port, leaving an unparseable host, so the function silently returns 0. Verification confirmed the IPC layer authenticates upstream — the test documents the current behaviour so that, if anyone ever calls extractCallerNode from a path without upstream auth, this test goes red.
  • No max-name-length validation: characterization test on a 64 KiB name documents that registration succeeds today. When a limit lands, the test should be flipped to assert rejection.

Honest-ceiling: the remaining 1.8%

  • json.MarshalIndent cannot fail for our snapshot types (no MarshalJSON hooks, no channels).
  • fsutil.AtomicWrite mid-write failure needs filesystem fault injection.
  • reapLoop's 60-second ticker tick branch is too racy to assert in a unit test (the done branch IS covered via Close()).
  • if rs.storePath == "" guards in save/load are unreachable through the public API once SetStorePath has been called.
  • len(lines) == 0 after strings.Split is unreachable — Split always returns at least one element.

Test plan

  • go test -race -count=1 -timeout 180s ./... passes locally
  • go vet ./... clean
  • Coverage report verified via go tool cover -func

…ests

Lift coverage from baseline 83.7% to 98.2% via a single new test file:

- Service adapter (service.go): from 0% to 100%; Name/Order/Start/Stop
  plus a cancelled-ctx regression pin so silent context handling fails
  loudly if anyone ever wires real Start logic.
- extractCallerNode (server.go): pin both the iter-2 audit
  characterization (plain "N:NNNN.HHHH.LLLL" silently returns 0 because
  net.SplitHostPort treats the first colon as host:port) AND the rarely-
  hit positive path (IPv6-bracketed pilot addr).
- handleRegister caller-mismatch: A and S records reject spoofed addrs.
- handleConn: bad-request flow + bare-close client doesn't crash the
  accept loop.
- ListenAndServe: bind failure error wrapping + Accept-after-Close.
- Client (client.go): dial / write / read / ERR-reply / malformed-reply
  paths for every Lookup* and Register* method (each was at ~67% before).
- RecordStore persistence (records.go): bad JSON load, snapshot with
  unparseable addrs in both A and S sections (skip-and-continue branch),
  no-file load, MkdirAll failure when storePath parent is a regular file,
  RegisterS rename-existing-entry path.
- reapExpired: A, N, and S record expiry paths in one shot.
- Wire (wire.go): QUERY A / QUERY N / REGISTER A,N,S short-form
  validation, ParseResponse skipping malformed / whitespace S lines,
  FormatRequest unknown-record-type defaulting to empty.

Also documents (not enforces) iter-2's "no max name length" finding via
a characterization test on a 64KiB name — when limits land, the test
must be replaced with an "ERR name too long" assertion.

Remaining 1.8% is honest ceiling: json.MarshalIndent error on our types
is impossible; fsutil.AtomicWrite mid-write failure needs filesystem
fault injection; reapLoop's 60s ticker branch is racy; defensive
storePath=="" / len(lines)==0 guards are unreachable through the public
API.

go test -race -count=1 -timeout 180s ./... passes.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 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 ad431d9 into main May 28, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 28, 2026 00:54
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