Skip to content

test(coverage): api internal/models ≥95%#159

Merged
mastermanas805 merged 1 commit into
masterfrom
coverage/api-models-95
May 22, 2026
Merged

test(coverage): api internal/models ≥95%#159
mastermanas805 merged 1 commit into
masterfrom
coverage/api-models-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

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 every internal/models source 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 transaction Begin/Commit/Rollback paths) are exercised via github.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

Metric Value
Package internal/models
Before 34.2%
After 98.7%
Command go test ./internal/models/... -short -count=1 -p 1 -covermode=atomic
Result ok 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.Read error branch in the *Plaintext token generators (GenerateAPIKeyPlaintext, GenerateMagicLinkPlaintext, GeneratePendingDeletionPlaintext, GeneratePromoteApprovalToken, GenerateStackSlug, generateVerificationToken, generateInviteToken, generatePromoCode). As of Go 1.26 crypto/rand.Read reads the OS getrandom syscall directly and panics on the practically-impossible failure rather than returning an error, ignoring the package Reader var — so the return "", err line is unreachable from a test without forking the runtime. Seam attempted: swapping crypto/rand.Reader for 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

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>
@mastermanas805 mastermanas805 merged commit 5203bc3 into master May 22, 2026
9 of 11 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