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:
@@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user