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,40 @@
|
||||
package onspring_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/StevanFreeborn/onspring-api-sdk-go"
|
||||
)
|
||||
|
||||
func TestOnspringAPIError(t *testing.T) {
|
||||
t.Run("it should create OnspringAPIError instance", func(t *testing.T) {
|
||||
statusCode := 500
|
||||
message := "Internal Server Error"
|
||||
|
||||
err := &onspring.OnspringAPIError{
|
||||
StatusCode: statusCode,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
if err.StatusCode != statusCode {
|
||||
t.Errorf("Expected status code %d, got %d", statusCode, err.StatusCode)
|
||||
}
|
||||
|
||||
if err.Message != message {
|
||||
t.Errorf("Expected message %s, got %s", message, err.Message)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("it should return formatted error message", func(t *testing.T) {
|
||||
err := &onspring.OnspringAPIError{
|
||||
StatusCode: 404,
|
||||
Message: "Not Found",
|
||||
}
|
||||
|
||||
expectedMessage := "onspring api error: status=404 message=Not Found"
|
||||
|
||||
if err.Error() != expectedMessage {
|
||||
t.Errorf("Expected error message %s, got %s", expectedMessage, err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user