-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Labels
good first issueGood for newcomersGood for newcomerssdk:goGo SDK relatedGo SDK relatedtestsUnit test improvements and coverageUnit test improvements and coverage
Description
Summary
Add unit tests for the Go SDK HTTP client error response parsing to ensure proper handling of various HTTP status codes and error formats.
Current State
- File:
sdk/go/client/client.go - Issue: Error response parsing paths are untested
What to Test
- APIError struct: Test parsing of error responses into
APIError - HTTP status codes: Test handling of 400, 401, 403, 404, 500, etc.
- Malformed responses: Test handling of invalid JSON error bodies
- Network errors: Test handling of connection failures
- Timeout handling: Test context cancellation behavior
Example Test Cases
func TestClient_APIErrorParsing(t *testing.T) {
tests := []struct {
name string
statusCode int
responseBody string
expectedError string
}{
{
name: "400 Bad Request",
statusCode: 400,
responseBody: `{"error": "invalid input"}`,
expectedError: "invalid input",
},
{
name: "404 Not Found",
statusCode: 404,
responseBody: `{"error": "resource not found"}`,
expectedError: "resource not found",
},
// ... more cases
}
// Test implementation
}Acceptance Criteria
- Tests cover various HTTP status codes (4xx, 5xx)
- Tests cover malformed response handling
- Tests use httptest for mocking HTTP responses
- All tests pass with
go test ./client/...
Files
- Source:
sdk/go/client/client.go - Test:
sdk/go/client/client_test.go(extend existing)
Using AI to solve this issue? Read our AI-Assisted Contributions guide for testing requirements, prompt strategies, and common pitfalls to avoid.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomerssdk:goGo SDK relatedGo SDK relatedtestsUnit test improvements and coverageUnit test improvements and coverage