Documentation
¶
Index ¶
- Constants
- type HTTPResponse
- type HTTPService
- type MockCall
- type MockHTTPService
- func (m *MockHTTPService) Delete(ctx context.Context, url string, headers map[string]string) (*HTTPResponse, error)
- func (m *MockHTTPService) Get(ctx context.Context, url string, headers map[string]string) (*HTTPResponse, error)
- func (m *MockHTTPService) Patch(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
- func (m *MockHTTPService) Post(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
- func (m *MockHTTPService) Put(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
- func (m *MockHTTPService) Reset()
- func (m *MockHTTPService) WithError(err error) *MockHTTPService
- func (m *MockHTTPService) WithGetResponse(statusCode int, body string) *MockHTTPService
- func (m *MockHTTPService) WithPostResponse(statusCode int, body string) *MockHTTPService
- func (m *MockHTTPService) WithResponse(statusCode int, body string) *MockHTTPService
Constants ¶
const (
// DefaultMaxResponseSize is the maximum size of response body to read (10MB)
DefaultMaxResponseSize = 10 * 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPResponse ¶
HTTPResponse stores the response from a request, including the payload and original response.
type HTTPService ¶
type HTTPService interface {
Get(ctx context.Context, url string, headers map[string]string) (*HTTPResponse, error)
Post(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
Put(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
Patch(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
Delete(ctx context.Context, url string, headers map[string]string) (*HTTPResponse, error)
}
HTTPService defines the interface for HTTP operations. This is the low-level HTTP layer that handles raw HTTP requests.
func NewHTTPService ¶ added in v1.2.0
NewHTTPService creates a new HTTPService with the specified configuration.
type MockHTTPService ¶ added in v1.2.0
type MockHTTPService struct {
// Response to return for all requests
Response *HTTPResponse
// Error to return for all requests
Error error
// Method-specific responses (takes precedence over Response)
GetResponse *HTTPResponse
GetError error
PostResponse *HTTPResponse
PostError error
PutResponse *HTTPResponse
PutError error
PatchResponse *HTTPResponse
PatchError error
DeleteResponse *HTTPResponse
DeleteError error
// Capture the last request for assertions
LastMethod string
LastURL string
LastHeaders map[string]string
LastBody string
CallCount int
CallHistory []MockCall
}
MockHTTPService is a mock implementation of HTTPService for testing
func NewMockHTTPService ¶ added in v1.2.0
func NewMockHTTPService() *MockHTTPService
NewMockHTTPService creates a new mock HTTP service
func (*MockHTTPService) Delete ¶ added in v1.2.0
func (m *MockHTTPService) Delete(ctx context.Context, url string, headers map[string]string) (*HTTPResponse, error)
Delete implements HTTPService.Delete
func (*MockHTTPService) Get ¶ added in v1.2.0
func (m *MockHTTPService) Get(ctx context.Context, url string, headers map[string]string) (*HTTPResponse, error)
Get implements HTTPService.Get
func (*MockHTTPService) Patch ¶ added in v1.2.0
func (m *MockHTTPService) Patch(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
Patch implements HTTPService.Patch
func (*MockHTTPService) Post ¶ added in v1.2.0
func (m *MockHTTPService) Post(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
Post implements HTTPService.Post
func (*MockHTTPService) Put ¶ added in v1.2.0
func (m *MockHTTPService) Put(ctx context.Context, url string, headers map[string]string, body string) (*HTTPResponse, error)
Put implements HTTPService.Put
func (*MockHTTPService) Reset ¶ added in v1.2.0
func (m *MockHTTPService) Reset()
Reset clears all recorded calls and responses
func (*MockHTTPService) WithError ¶ added in v1.2.0
func (m *MockHTTPService) WithError(err error) *MockHTTPService
WithError sets the default error for all methods
func (*MockHTTPService) WithGetResponse ¶ added in v1.2.0
func (m *MockHTTPService) WithGetResponse(statusCode int, body string) *MockHTTPService
WithGetResponse sets a specific response for GET requests
func (*MockHTTPService) WithPostResponse ¶ added in v1.2.0
func (m *MockHTTPService) WithPostResponse(statusCode int, body string) *MockHTTPService
WithPostResponse sets a specific response for POST requests
func (*MockHTTPService) WithResponse ¶ added in v1.2.0
func (m *MockHTTPService) WithResponse(statusCode int, body string) *MockHTTPService
WithResponse sets the default response for all methods