test(mongo): drive backend/mongo coverage to 96.2%#25
Merged
Conversation
Covers the MongoDB LocalBackend (CREATE USER with DB-scoped readWrite role, deprovision dropping user+db, storage scan) and the K8sBackend orchestration end-to-end against a real mongod (no-auth + authed fixtures) and a fake clientset. Two small testability seams, mirroring the existing initMongoFn pattern: - LocalBackend.connectFn: makes the lazy-connect / disconnect-error arms deterministically reachable (the real driver almost never errors on Connect). - K8sBackend.mongoPort + shared decodeStorageSize helper: lets the dbStats decode arms (int32/int64/float64/absent) be exercised without a cluster. Remaining uncovered lines are genuinely defensive (crypto/rand failure, multi-minute readiness/terminating deadlines, retry give-up) and not reachable without mocking the driver or multi-minute tests. 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
provisioner/internal/backend/mongocoverage to 96.2% (statements), exceeding the 95% target.LocalBackendend-to-end: CREATE USER with areadWriterole scoped to a single DB, deprovision (drops user + database, idempotent on missing), storage-size scan, pool-token (PRID) routing, dedup/conflict, and connect/disconnect error arms.K8sBackendorchestration: Provision happy-path tail (publicHost + NodePort URL builders, route-registry writes), all rollback branches,waitPodReady,initMongo/tryInitMongo, andStorageBytes(fail-soft + successful dbStats decode).Approach
Tests run against real
mongo:6fixtures (a no-auth instance viaCUSTOMER_MONGO_URLand an authed instance viaCUSTOMER_MONGO_AUTH_URL) plus a fake k8s clientset; every live-dependent test skips cleanly when its fixture is absent, so CI without Mongo stays green.Two small testability seams were added, mirroring the existing
initMongoFnpattern:LocalBackend.connectFn— makes the lazy-connect / disconnect-error arms deterministically reachable (the real driver almost never errors onConnect; a bad URI surfaces lazily on firstRunCommand).K8sBackend.mongoPort+ a shareddecodeStorageSizehelper — lets the dbStatsstorageSizedecode arms (int32 / int64 / float64 / absent) be unit-tested without a cluster (a livemongodonly ever emits float64).Remaining uncovered lines are genuinely defensive:
crypto/randfailure, multi-minute readiness / terminating-namespace deadlines, and the 30s+ retry give-up — none reachable without mocking the driver or multi-minute tests.Test plan
go test ./internal/backend/mongo -coverprofile=cov.out -covermode=set -count=1 -p 1→coverage: 96.2% of statementsgo build ./...+go vet ./internal/backend/mongocleanorigin/master(passes the up-to-date-with-base gate)🤖 Generated with Claude Code