test(coverage): drive db/cache/nosql local providers (91.1/88.9/85.9%)#148
Closed
mastermanas805 wants to merge 1 commit into
Closed
test(coverage): drive db/cache/nosql local providers (91.1/88.9/85.9%)#148mastermanas805 wants to merge 1 commit into
mastermanas805 wants to merge 1 commit into
Conversation
Adds real-backend + white-box unit tests for the three local-backend providers: - db: 2.2% -> 91.1% (local CREATE DATABASE/USER lifecycle, name derivation, dup-provision, connect/storage/drop error branches, the full neon HTTP backend via an injected RoundTripper, and the provider factory/delegation) - cache: 64.8% -> 88.9% (New defaults, legacy/ full ACL username derivation, nil-client + Upstash-stub + ACL->key-namespace fallback, SCAN error, vanished-key skip) - nosql: 70.3% -> 85.9% (New defaults, dup-user createUser error, positive StorageBytes, dropUser non-fatal, connect-error branches, init-insert + dbStats fail-open) Tests are CI-safe: they skip cleanly when TEST_CUSTOMERS_URL / TEST_REDIS_URL / TEST_MONGO_URI (and the optional TEST_CUSTOMERS_LIMITED_URL for privilege-failure branches) are unset. The remaining uncovered statements in each file are defensive code that is not deterministically unit-testable against real backends without production source seams: crypto/rand failures, pgx Close / mongo.Disconnect defer-error logs (no error on a cancelled ctx), the 200k-key StorageBytes truncation ceiling (O(keys) MEMORY USAGE round-trips), and owner-only REVOKE/GRANT branches that cannot fail for the role that just created the database. None reached the >=95% target; see the PR body for the per-branch blocker analysis. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
Member
Author
|
Superseded by #151, which reaches the >=95% mandate on all three packages (db 97.8% / cache 98.2% / nosql 100%) using deterministic source seams instead of waivers. #151 also fixes the env-var mismatch in this PR (TEST_CUSTOMERS_URL -> TEST_POSTGRES_CUSTOMERS_URL — these tests silently skipped in CI here) and replaces the timing-based MEMORY-USAGE-skip test with a deterministic interface fake. |
mastermanas805
added a commit
that referenced
this pull request
May 22, 2026
…rce seams (#151) 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds real-backend integration + white-box unit tests for the three local-backend providers in
internal/providers/.internal/providers/dbinternal/providers/cacheinternal/providers/nosqlWhat's covered: provision + deprovision happy paths, name/identifier derivation, idempotent re-provision, duplicate-resource conflicts, connection-failure branches, ACL allowlist + key-namespace fallback, the full Neon HTTP backend (via an injected
RoundTripper), and the provider factory/delegation layer.Tests skip cleanly when
TEST_CUSTOMERS_URL/TEST_REDIS_URL/TEST_MONGO_URIare unset, so a barego test ./...stays green. The privilege-failure branches (DROP DATABASE / DROP USER denied) use an optionalTEST_CUSTOMERS_LIMITED_URLnon-superuser DSN.Did NOT reach the ≥95% target — honest status
The remaining uncovered statements in each file are defensive code that is not deterministically unit-testable against real backends without adding production source seams. None of the three hit 95%:
crypto/randfailures; pgxconn.Close(ctx)defer-error logs (verified: a cancelled ctx does not make Close error); the REVOKE CONNECT / GRANT PRIVILEGES / GRANT SCHEMA non-fatal logs (the role that just created the DB owns it, so these can't fail); the connect-to-just-created-DB branch (always succeeds).crypto/rand.Readfailure; the 200k-keyStorageBytestruncation ceiling (one MEMORY USAGE round-trip per key → multi-minute, times out CI); the mid-scan key-deletion skip (timing race, would be flaky).mongo.Disconnectdefer-error logs;crypto/rand.Read; dbStats / drop-database errors that don't fire under a root connection.Reaching ≥95% would require either flaky timing-dependent tests, an impractically slow 200k-key write, or refactoring the production source to inject fault-on-demand stdlib seams (rand source, mongo client factory, lowered constants). Flagging for a decision rather than shipping flaky tests or unrelated source churn.
Test plan
go test ./internal/providers/{db,cache,nosql} -count=1 -p 1green against local docker pg(16)/redis(7)/mongo(6) on 127.0.0.1go test ... -shortgreen (graceful skip) with no env varsgofmt -lclean,go vetclean🤖 Generated with Claude Code