Skip to content

test(razorpaybilling): drive coverage 8.5% -> 100%#140

Merged
mastermanas805 merged 1 commit into
masterfrom
coverage/api-razorpay-95
May 21, 2026
Merged

test(razorpaybilling): drive coverage 8.5% -> 100%#140
mastermanas805 merged 1 commit into
masterfrom
coverage/api-razorpay-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • Adds internal/razorpaybilling/portal_coverage_test.go covering every Portal method, both pure helpers (toInt64, pickInvoiceTimestamp), and every callWithBreaker branch including the singleton's open-state rejection and WithOnOpen callback.
  • One-line test seam in portal.go: newClientForPortal (defaults to NewTimeoutClient) lets tests retarget the SDK's BaseURL at an httptest.Server. Production callers go through the original constructor unchanged.
  • All Razorpay REST shapes are mocked locally — no live API hits, no DB hits (sqlmock for SubscriptionID and ChangePlan persistence).

Coverage

  • Baseline: 8.5%
  • After: 100.0% of statements
  • Per-func: every function at 100% (verified via go tool cover -func).

Test plan

  • go test ./internal/razorpaybilling -coverprofile=cov.out -count=1 -> 100.0%
  • go test ./internal/razorpaybilling -race -count=1 -> pass
  • go vet ./internal/razorpaybilling/... -> clean
  • go build ./internal/razorpaybilling/... -> clean
  • CI gate (test + vet) green on the PR

Notes:

  • The singleton-breaker test runs LAST in source order; it intentionally leaves the singleton open (the only way to cover the rejection branch). All preceding tests reset the singleton's consecutive-failure counter via t.Cleanup(resetBreaker) so ordering across the rest of the file is irrelevant.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Generated with Claude Code

Every Portal method (SubscriptionID, CancelAtCycleEnd, CancelImmediately,
ListSubscriptionInvoices, PaymentUpdateURL, ChangePlan,
FetchSubscriptionDetails) plus the toInt64 / pickInvoiceTimestamp
helpers now exercise their happy path, every error branch (4xx/5xx
upstream, no-config, DB error, sql.ErrNoRows, malformed/missing fields),
and every callWithBreaker arm — including the open-state rejection
and the WithOnOpen callback on the singleton breaker.

The Razorpay REST surface is mocked via httptest.Server; no live API
calls. A one-line test seam in portal.go (newClientForPortal) lets
tests retarget the SDK's BaseURL at the mock; production callers go
through the original NewTimeoutClient unchanged.

Coverage: 8.5% -> 100.0% of statements (go test -cover).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805 mastermanas805 merged commit 435002b into master May 21, 2026
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