Documentation
¶
Overview ¶
Package testutil provides doubles and fixture helpers for the paystack-go test suite. It lives under internal/ so it cannot be imported outside this module.
Index ¶
- func AssertErrorMatrix(t *testing.T, invoke func(paystack.Backend) error)
- func LoadFixture(t testing.TB, name string) []byte
- func RunConcurrent(t *testing.T, n int, fn func() error)
- type CallRecord
- type ErrorCase
- type FixtureBackend
- type MockBackend
- func (m *MockBackend) Call(ctx context.Context, method, path string, params, out interface{}) error
- func (m *MockBackend) CallRaw(ctx context.Context, method, path string, params interface{}) (*http.Response, error)
- func (m *MockBackend) Calls() []CallRecord
- func (m *MockBackend) LastCall() CallRecord
- func (m *MockBackend) Reset()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertErrorMatrix ¶
AssertErrorMatrix runs DefaultErrorMatrix against invoke. invoke is called once per row with a FixtureBackend wired to that row's fixture and must return the service method's error.
func LoadFixture ¶
LoadFixture reads a file from testdata/ relative to the module root. It fails the test immediately if the fixture cannot be read.
Types ¶
type CallRecord ¶
CallRecord captures one invocation of MockBackend.Call or .CallRaw.
type ErrorCase ¶
type ErrorCase struct {
Name string
Fixture string
Status int
Header http.Header
WantCode paystack.ErrorCode
WantRetry time.Duration
WantFields bool
}
ErrorCase captures one row of the standard error matrix every service method must pass. Use AssertErrorMatrix to run the whole table in a single test.
func DefaultErrorMatrix ¶
func DefaultErrorMatrix() []ErrorCase
DefaultErrorMatrix returns the seven error rows every service method is required to handle by the spec.
type FixtureBackend ¶
type FixtureBackend struct {
// Fixture is a filename under testdata/ (e.g. "transaction_verify.json").
Fixture string
// Status is the HTTP status to simulate. Defaults to 200.
Status int
// Header lets tests inject response headers (e.g. Retry-After).
Header http.Header
}
FixtureBackend serves a fixture file as if it were a live Paystack response. When Status >= 400, the body is passed through paystack.ParseError so the returned *Error matches what HTTPBackend would produce.
type MockBackend ¶
type MockBackend struct {
// Response is JSON-encoded into the caller's `out` when non-nil and Err
// is nil. It can be a ready-made Response[T] / ListResponse[T] envelope
// or a plain struct — the bytes are marshalled then unmarshalled.
Response interface{}
// Err, when set, is returned as-is from Call.
Err error
// RawResponse drives CallRaw. When nil, an empty 200 is returned.
RawResponse *http.Response
// contains filtered or unexported fields
}
MockBackend is a Backend double with fully controllable responses. Use it when the test is about call shape (method, path, params) rather than response parsing.
func (*MockBackend) Call ¶
func (m *MockBackend) Call(ctx context.Context, method, path string, params, out interface{}) error
Call records the invocation and either returns Err or JSON-round-trips Response into out.
func (*MockBackend) CallRaw ¶
func (m *MockBackend) CallRaw(ctx context.Context, method, path string, params interface{}) (*http.Response, error)
CallRaw records the invocation and returns RawResponse or a default 200.
func (*MockBackend) Calls ¶
func (m *MockBackend) Calls() []CallRecord
Calls returns a copy of all recorded invocations.
func (*MockBackend) LastCall ¶
func (m *MockBackend) LastCall() CallRecord
LastCall returns the most recent recorded invocation. Panics if none.