Skip to content

test(providers/db): drive coverage 2.2% → 95.6%#144

Closed
mastermanas805 wants to merge 1 commit into
masterfrom
coverage/api-providers-db-95
Closed

test(providers/db): drive coverage 2.2% → 95.6%#144
mastermanas805 wants to merge 1 commit into
masterfrom
coverage/api-providers-db-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • Added four test files (local_unit_test.go, provider_test.go, neon_test.go, local_integration_test.go) covering every reachable branch in api/internal/providers/db.
  • Introduced three minimal package-level seams in local.go (randReader, newDBConnect, adminConnect) — each defaults to the production implementation and only differs when a test reassigns it. Production behaviour is unchanged.
  • Coverage 2.2% → 95.6% (174/182 statements). Remaining 8 uncovered statements are deeply defensive defer-close error logs and impossible JSON-marshal-of-static-map paths that would require mocking pgx.Conn itself.

Test plan

  • TEST_POSTGRES_CUSTOMERS_URL set: 30+ tests pass, coverage 95.6%, three consecutive runs green.
  • TEST_POSTGRES_CUSTOMERS_URL unset: integration tests skip cleanly; pure-unit + Neon + Provider tests still pass.
  • go build ./... and go vet ./... clean repo-wide.

🤖 Generated with Claude Code

Add four test files exercising every reachable branch in
api/internal/providers/db:

- local_unit_test.go — pure-unit coverage of the no-network helpers
  (extractHost / indexOf / buildDBURL / buildAdminNewDBURL,
  generatePassword's charset+length+rand-error branch, newLocalBackend
  default-URL substitution).

- provider_test.go — Provider facade dispatcher: New() picks Local by
  default, Neon when configured; all four methods faithfully forward
  to the configured Backend with args and errors propagating verbatim.

- neon_test.go — NeonBackend via httptest.Server with a rewrite
  Transport. Covers happy-path, every error branch (non-2xx,
  malformed JSON, missing project ID, no connection_uris, network
  unreachable, body-read truncation via Hijack, control-char URL),
  the extensions-not-supported path, and the inner-Provision-fails
  branch of ProvisionWithExtensions.

- local_integration_test.go — LocalBackend against TEST_POSTGRES_CUSTOMERS_URL.
  Covers Provision happy-path, the vector-extension install, the
  rejected-extension validator, CREATE DATABASE duplicate, CREATE
  USER duplicate (post-crash state), StorageBytes happy + missing-db
  + connect-fail, Deprovision happy + idempotent + connect-fail, the
  DROP USER non-fatal branch (user owns objects), full-token vs short-
  prefix naming, and the deterministic new-DB-connect-fail and admin-
  conn-pre-killed paths via tiny package-level seams (newDBConnect /
  adminConnect / randReader). Tests skip cleanly when
  TEST_POSTGRES_CUSTOMERS_URL is unset so CI without a postgres
  service container stays green.

The three new package-level seams in local.go (randReader,
newDBConnect, adminConnect) default to the production implementations
and only differ when a test reassigns them. Production behaviour is
unchanged.

Coverage: 2.2% → 95.6% (174/182 statements). Remaining 8 uncovered
statements are deeply defensive defer-close error logs and impossible
JSON-marshal-of-static-map paths that would require mocking pgx.Conn
itself; the cost of further DI was judged to outweigh the marginal
coverage gain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805
Copy link
Copy Markdown
Member Author

Superseded by #151 (providers db/cache/nosql to ≥95% via deterministic seams; merged).

@mastermanas805 mastermanas805 deleted the coverage/api-providers-db-95 branch May 22, 2026 03:43
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