-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Add Context Support and Improve Readability by jamieaitken #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
3647be0 to
f015738
Compare
f015738 to
e9d71b4
Compare
e9d71b4 to
91f3712
Compare
|
@jamieaitken next week we will release this version, thank you. |
|
@armando-rodriguez-cko great, thanks for keeping me in the loop! |
91f3712 to
b6f1402
Compare
|
After reviewing and evaluating this PR, it is closed for now due to the need to add more context tests and better cover all areas and endpoints with context. The branch will remain active to add these fixes; we apologise for the inconvenience. |
8631a7c to
8386d75
Compare
|
|
@jamieaitken reopened and rebased, we will work on this soon. |
* Add Context to HTTP layer * Add Context to Customers client * Add Context to Disputes client * Add Context to Events client * Add Context to Hosted client * Add Context to Instruments client * Add Context to Links client * Add Context to Payments client * Add Context to Reconciliation client * Add Context to Sources client * Add Context to Tokens client * Add Context to Webhook client * Add Context to iDEAL client * Add Context to Klarna client * Add Context to SEPA client * Update tests * Add Context to NAS Payments --------- Co-authored-by: Armando Rodríguez <[email protected]>
8386d75 to
669a10e
Compare
* Subdomain added for access validation endpoint * Access domain test updates --------- Co-authored-by: david ruiz <[email protected]>
- Subdomain added for access validation endpoint - Access domain test updates
…ontext support - Added TestGetAllReports with 3 test cases: success, auth error, API error - Added TestGetReportDetails with 3 test cases: success, auth error, not found - Added TestGetReportFile with 3 test cases: success, auth error, not found - All tests follow established mock pattern with GetWithContext - Resolves missing test coverage for reports package - Tests pass: 9/9 passed
- TestContextCancellation: verify context.Canceled is propagated - TestContextTimeout: verify timeout triggers fast abort - TestContextTimeoutSuccess: verify generous timeout allows completion - TestContextPropagation: verify context values reach HTTP server - TestDefaultMethodUsesBackgroundContext: verify fallback behavior - TestConcurrentRequestsWithDifferentContexts: verify isolation - TestContextPostWithCancellation/PutWithCancellation/DeleteWithCancellation: all HTTP verbs - TestContextDeadline: verify absolute deadline handling - Tests pass: 10/10
- Added ForwardPaymentWithContext method - Updated ForwardPaymentWithTests mock pattern - Backward compatible: Forward() calls ForwardPaymentWithContext(context.Background()) - Tests pass: 6/6
- Added CreatePaymentContextWithContext method - Backward compatible: CreatePaymentContext() uses context.Background()
- Added four WithContext methods: RequestPaymentSessionWithContext, GetPaymentSessionWithContext, UpdatePaymentSessionWithContext, CompletePaymentSessionWithContext - Updated test mocks for PostWithContext/PutWithContext pattern - All tests pass: 12/12
- Added four WithContext methods: CreatePaymentSetupWithContext, UpdatePaymentSetupWithContext, GetPaymentSetupWithContext, ConfirmPaymentSetupWithContext - Updated test mocks for PostWithContext/PutWithContext pattern - All tests pass: 12/12
- Fixed type name inconsistencies: HostedPayment* -> PaymentHosted* - Added CreatePaymentHostedWithContext method - Updated test mocks to use corrected type names - Pattern: CreatePaymentHosted() calls CreatePaymentHostedWithContext(context.Background()) - Tests pass: 6/6
- Added GetAllReportsWithContext, GetReportDetailsWithContext, GetReportFileWithContext methods - Backward compatible: existing methods use context.Background()
…vidence - Added GetCompiledSubmittedEvidenceWithContext method - Backward compatible: GetCompiledSubmittedEvidence() uses context.Background()
- Added IncrementAuthorizationWithContext method - Added CapturePaymentWithoutRequestWithContext method - Backward compatible: existing methods use context.Background()
…houtRequest - Added CapturePaymentWithoutRequestWithContext method - Backward compatible: CapturePaymentWithoutRequest() uses context.Background()
|
@jamieaitken new attempt 🤞🏼 |
- Updated doRequest to accept and pass context to handleResponse - Updated handleResponse to accept context and pass to readBody - Updated readBody to check context.Done() before reading body - Ensures context cancellation/timeout is respected during response parsing - Added 5 new tests to verify context propagation: * TestReadBodyContextCancellation: readBody respects cancelled context * TestHandleResponseContextPropagation: handleResponse receives context * TestHandleResponseContextCancellation: handleResponse aborts on cancellation * TestContextPropagationThroughDoRequest: full propagation through chain * TestFullRequestContextFlow: end-to-end context flow - All 15/15 client tests pass
|



feat: Add Context Support and Improve Readability
Description:
This PR introduces
WithContextvariants for all publicly exposed methods in the Go SDK clients. These changes provide developers with fine-grained control over timeouts and cancellations using Go’s nativecontext.Context. Additionally, method signatures and calls have been refactored for improved readability and consistency.Key Changes:
Context Support
WithContextversions of all public methods across SDK clients.CreateWithContext,GetWithContext,UpdateWithContext,DeleteWithContext, etc.WithContextcounterparts usingcontext.Background().Improved Readability
No Functional Changes
Impact
Testing
WithContextversions internally delegate to the correct context-aware HTTP client functions (PostWithContext,GetWithContext, etc.).Notes
WithContextversions going forward.