Skip to content

test(mongo): drive backend/mongo coverage to 96.2%#25

Merged
mastermanas805 merged 1 commit into
masterfrom
coverage/prov-backend-mongo-95
May 22, 2026
Merged

test(mongo): drive backend/mongo coverage to 96.2%#25
mastermanas805 merged 1 commit into
masterfrom
coverage/prov-backend-mongo-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • Drives provisioner/internal/backend/mongo coverage to 96.2% (statements), exceeding the 95% target.
  • Covers the MongoDB LocalBackend end-to-end: CREATE USER with a readWrite role 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.
  • Covers the K8sBackend orchestration: Provision happy-path tail (publicHost + NodePort URL builders, route-registry writes), all rollback branches, waitPodReady, initMongo/tryInitMongo, and StorageBytes (fail-soft + successful dbStats decode).

Approach

Tests run against real mongo:6 fixtures (a no-auth instance via CUSTOMER_MONGO_URL and an authed instance via CUSTOMER_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 initMongoFn pattern:

  • LocalBackend.connectFn — makes the lazy-connect / disconnect-error arms deterministically reachable (the real driver almost never errors on Connect; a bad URI surfaces lazily on first RunCommand).
  • K8sBackend.mongoPort + a shared decodeStorageSize helper — lets the dbStats storageSize decode arms (int32 / int64 / float64 / absent) be unit-tested without a cluster (a live mongod only ever emits float64).

Remaining uncovered lines are genuinely defensive: crypto/rand failure, 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 1coverage: 96.2% of statements
  • go build ./... + go vet ./internal/backend/mongo clean
  • Branch rebased onto latest origin/master (passes the up-to-date-with-base gate)

🤖 Generated with Claude Code

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>
@mastermanas805 mastermanas805 merged commit 0dc1cf4 into master May 22, 2026
9 of 10 checks passed
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