test(providers/db): drive coverage 2.2% → 95.6%#144
Closed
mastermanas805 wants to merge 1 commit into
Closed
Conversation
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>
Member
Author
|
Superseded by #151 (providers db/cache/nosql to ≥95% via deterministic seams; merged). |
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
local_unit_test.go,provider_test.go,neon_test.go,local_integration_test.go) covering every reachable branch inapi/internal/providers/db.local.go(randReader,newDBConnect,adminConnect) — each defaults to the production implementation and only differs when a test reassigns it. Production behaviour is unchanged.pgx.Connitself.Test plan
TEST_POSTGRES_CUSTOMERS_URLset: 30+ tests pass, coverage 95.6%, three consecutive runs green.TEST_POSTGRES_CUSTOMERS_URLunset: integration tests skip cleanly; pure-unit + Neon + Provider tests still pass.go build ./...andgo vet ./...clean repo-wide.🤖 Generated with Claude Code