feat: initialize client core and ping endpoint

establishes the foundational architecture for the Onspring Go SDK.

changes included:
- add `Client` struct and `NewClient` constructor with authentication.
- implement functional options pattern (WithHTTPClient, WithBaseURL, etc.).
- add `OnspringAPIError` type for handling non-2xx responses.
- implement internal request construction and execution logic.
- add `Ping` service for API health check verification.
- add comprehensive unit tests and mock server infrastructure.
This commit is contained in:
Stevan Freeborn
2025-12-05 21:33:23 -06:00
parent 3098779596
commit a9e49906e0
10 changed files with 568 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package onspring_test
import (
"net/http"
"testing"
"time"
"github.com/StevanFreeborn/onspring-api-sdk-go"
)
func TestWithHTTPClient(t *testing.T) {
t.Run("it should set a custom HTTP client on the Onsring client", func(t *testing.T) {
customHTTPClient := &http.Client{Timeout: 10 * time.Second}
clientWithCustomHTTP := onspring.NewClient(
"test-api-key",
onspring.WithHTTPClient(customHTTPClient),
)
if clientWithCustomHTTP.HTTPClient() != customHTTPClient {
t.Errorf("Expected custom HTTP client to be set")
}
})
}
func TestWithBaseURL(t *testing.T) {
t.Run("it should set a custom base URL on the Onsring client", func(t *testing.T) {
customBaseURL := "https://custom.onspring.com"
clientWithCustomURL := onspring.NewClient(
"test-api-key",
onspring.WithBaseURL(customBaseURL),
)
if clientWithCustomURL.BaseURL() != customBaseURL {
t.Errorf("Expected base URL to be %s, got %s", customBaseURL, clientWithCustomURL.BaseURL())
}
})
}
func TestWithAPIVersion(t *testing.T) {
t.Run("it should set a custom API version on the Onsring client", func(t *testing.T) {
customVersion := "3.0"
clientWithCustomVersion := onspring.NewClient(
"test-api-key",
onspring.WithAPIVersion(customVersion),
)
if clientWithCustomVersion.APIVersion() != customVersion {
t.Errorf("Expected API version to be %s, got %s", customVersion, clientWithCustomVersion.APIVersion())
}
})
}