Skip to content

test(coverage): db/cache/nosql local providers to >=95% via source seams#151

Merged
mastermanas805 merged 1 commit into
masterfrom
coverage/api-providers-seams-95
May 22, 2026
Merged

test(coverage): db/cache/nosql local providers to >=95% via source seams#151
mastermanas805 merged 1 commit into
masterfrom
coverage/api-providers-seams-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

Closes the coverage gap on the three local-backend providers to the >=95% mandate using deterministic source seams (org policy now requires seams, not waivers). Production defaults are unchanged — every seam defaults to the real fn/value.

Package Before After
internal/providers/db 2.2% 97.8% (local.go fully covered)
internal/providers/cache 64.8% 98.2%
internal/providers/nosql 70.3% 100.0%

Seams added (package vars / interfaces, real default)

  • db/local.gorandInt (crypto/rand.Int), pgConn interface + pgxConnect factory. An in-memory fake pgConn drives the RNG failure, the conn.Close defer-error logs, and the non-fatal REVOKE / GRANT / DROP USER exec-error logs.
  • cache/redis.gorandRead (crypto/rand.Read); storageBytesScanCap (test-lowerable truncation ceiling, default storageMaxKeys=200k); redisScanner interface behind a storageBytes helper. The mid-scan vanished-key skip is now deterministic (a fake returns a SCAN key that MEMORY USAGE reports missing); the truncation branch fires with a handful of keys (no 200k write, no timing).
  • nosql/mongo.gorandRead (crypto/rand.Read); mongoDisconnect seam for the Disconnect defer-error logs; storageSizeToInt64 extracted so every numeric BSON arm is unit-testable.

Notable fixes over the prior attempt (supersedes #148)

  • Replaced the flaky timing-based MEMORY-USAGE-skip test with a deterministic interface fake.
  • Aligned the db test env var to TEST_POSTGRES_CUSTOMERS_URL (what CI's coverage.yml provides). The prior attempt used TEST_CUSTOMERS_URL and silently skipped in CI, contributing zero coverage.
  • Hardened uniqueToken with a per-run random seed so same-second runs against a shared Postgres can't collide with orphan databases.

Test plan

  • go test ./internal/providers/{db,cache,nosql} -count=1 -p 1 green against local docker pg16 / redis7 / mongo6 on 127.0.0.1
  • Per-package coverage all >=95% (97.8 / 98.2 / 100.0)
  • Stable across 3 consecutive full runs (no flake)
  • CI-safe: clean skip with no env vars; go build ./... + go vet ./... clean; gofmt -l clean
  • CI gate (coverage / ci / deploy) green on this PR

🤖 Generated with Claude Code

…rce seams

Closes the coverage gap on the three local-backend providers to the >=95%
mandate using deterministic source seams (org policy: seams, not waivers).
Production defaults are identical — every seam defaults to the real
fn/value.

Coverage (per-package, real pg16/redis7/mongo6 on 127.0.0.1):
- internal/providers/db:    2.2%  -> 97.8%  (local.go fully covered)
- internal/providers/cache: 64.8% -> 98.2%
- internal/providers/nosql: 70.3% -> 100.0%

Seams added (all package vars / interfaces, real default):
- db/local.go:    randInt (crypto/rand.Int), pgConn interface + pgxConnect
  factory — drives the RNG failure, conn.Close defer-error logs, and the
  non-fatal REVOKE/GRANT/DROP USER exec-error logs via an in-memory fake.
- cache/redis.go: randRead (crypto/rand.Read); storageBytesScanCap
  (test-lowerable truncation ceiling, default storageMaxKeys=200k);
  redisScanner interface behind storageBytes — drives the mid-scan
  vanished-key skip deterministically (fake returns a SCAN key that
  MEMORY USAGE reports missing) and the truncation branch with a handful
  of keys (no 200k write, no timing).
- nosql/mongo.go: randRead (crypto/rand.Read); mongoDisconnect seam for
  the Disconnect defer-error logs; storageSizeToInt64 extracted so every
  numeric BSON arm is unit-testable.

Replaces the flaky timing-based MEMORY-USAGE-skip test from the prior
attempt with a deterministic interface fake. Aligns the db test env var
to TEST_POSTGRES_CUSTOMERS_URL (what CI's coverage.yml provides; the prior
attempt used TEST_CUSTOMERS_URL and silently skipped in CI). Hardens
uniqueToken with a per-run random seed so same-second runs against a
shared Postgres can't collide.

Tests are CI-safe (skip cleanly with no env) and stable across 3
consecutive full runs. Supersedes PR #148.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805 mastermanas805 merged commit 849058e into master May 22, 2026
10 of 11 checks passed
@mastermanas805 mastermanas805 deleted the coverage/api-providers-seams-95 branch May 22, 2026 02:48
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