test(coverage): api internal/models ≥95%#159
Merged
Merged
Conversation
Add white-box sqlmock-driven branch coverage for every internal/models source file. Pure test-only additions — no production code changed. Each function's happy path, sql.ErrNoRows / sentinel-error branches, rows-affected guards, scan failures, rows.Err iteration errors, and transaction begin/commit/rollback paths are exercised via go-sqlmock so DB-error branches that can't be hit against a healthy Postgres are covered deterministically. models coverage: 34.2% → 98.7% (go test ./internal/models/... -short -p 1 -covermode=atomic). Remaining sub-95% functions are the crypto/rand.Read error branch in the *Plaintext token generators, which is unreachable in Go 1.26 (crypto/rand.Read reads the OS getrandom syscall directly and panics rather than returning an error, ignoring the package Reader var). 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
Closes the coverage gap on
internal/models. Pure test-only change — no production source modified.Adds white-box (
package models) sqlmock-driven branch coverage for everyinternal/modelssource file. Each function's happy path plus its DB-error branches (sql.ErrNoRows, sentinel errors, rows-affected guards, scan failures,rows.Err()iteration errors, and transactionBegin/Commit/Rollbackpaths) are exercised viagithub.com/DATA-DOG/go-sqlmock, so error branches that can't be reached against a healthy Postgres are covered deterministically. Existing real-DB integration tests are left intact.Coverage block
internal/modelsgo test ./internal/models/... -short -count=1 -p 1 -covermode=atomicok instant.dev/internal/models coverage: 98.7% of statements(exit 0)Files touched (all new, test-only)
29 new files under
internal/models/:coverage_helpers_test.go(shared sqlmock plumbing) + per-source-file suites:coverage_admin_customer_notes_test.go,coverage_admin_promo_codes_test.go,coverage_api_key_test.go,coverage_app_github_connection_test.go,coverage_audit_log_test.go,coverage_backup_test.go,coverage_custom_domain_test.go,coverage_deployment_event_test.go,coverage_deployment_test.go,coverage_deploys_audit_test.go,coverage_email_events_test.go,coverage_env_policy_test.go,coverage_magic_link_test.go,coverage_onboarding_test.go,coverage_payment_grace_test.go,coverage_pending_checkouts_test.go,coverage_pending_deletion_test.go,coverage_promote_approvals_test.go,coverage_provision_gate_test.go,coverage_resource_family_test.go,coverage_resource_test.go,coverage_stack_test.go,coverage_team_deletion_test.go,coverage_team_invitations_test.go,coverage_team_members_test.go,coverage_team_test.go,coverage_vault_test.go,coverage_extra_test.go.Functions still < 95% (reason)
The only remaining sub-95% functions are the
crypto/rand.Readerror branch in the*Plaintexttoken generators (GenerateAPIKeyPlaintext,GenerateMagicLinkPlaintext,GeneratePendingDeletionPlaintext,GeneratePromoteApprovalToken,GenerateStackSlug,generateVerificationToken,generateInviteToken,generatePromoCode). As of Go 1.26crypto/rand.Readreads the OS getrandom syscall directly and panics on the practically-impossible failure rather than returning an error, ignoring the packageReadervar — so thereturn "", errline is unreachable from a test without forking the runtime. Seam attempted: swappingcrypto/rand.Readerfor a failing reader (no longer honored in Go 1.26). These functions sit at ~75% (the one unreachable line), which is why the package total is 98.7% rather than 100%. The package total is comfortably above the 95% floor.🤖 Generated with Claude Code