Skip to content

[Go SDK] Add tests for client error response parsing #112

@santoshkumarradha

Description

@santoshkumarradha

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

  1. APIError struct: Test parsing of error responses into APIError
  2. HTTP status codes: Test handling of 400, 401, 403, 404, 500, etc.
  3. Malformed responses: Test handling of invalid JSON error bodies
  4. Network errors: Test handling of connection failures
  5. 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.

Metadata

Metadata

Labels

good first issueGood for newcomerssdk:goGo SDK relatedtestsUnit test improvements and coverage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions