Documentation
¶
Overview ¶
Package queuetest provides MockQueue, a mock of core's gas.JobQueueProvider for tests. It shows that a caller is wired to enqueue and consume jobs correctly, not that a backend works; the sqs backend has its own tests.
Role in the framework ¶
MockQueue implements gas.JobQueueProvider. Each method records the call and delegates to its function field (EnqueueFn, DequeueFn, AckFn, NackFn) when set; otherwise it returns zero values (a nil error, and no jobs from Dequeue).
mock := &queuetest.MockQueue{}
mock.EnqueueFn = func(ctx context.Context, queue string, payload []byte, opts ...gas.EnqueueOption) error {
return nil
}
Wiring, configuration and lifecycle ¶
A test passes the mock wherever a gas.JobQueueProvider is expected, in place of a real backend. The package reads no configuration, has no lifecycle and starts no goroutines.
Invariants ¶
Recording and the CallCount and Reset methods are safe for concurrent use. The Calls field is not guarded for readers: read it directly only after the calls under test have finished, or use CallCount.
SPDX-License-Identifier: MIT
Index ¶
- type Call
- type MockQueue
- func (m *MockQueue) Ack(ctx context.Context, queue string, job gas.Job) error
- func (m *MockQueue) CallCount(method string) int
- func (m *MockQueue) Dequeue(ctx context.Context, queue string, maxMessages int, wait time.Duration) ([]gas.Job, error)
- func (m *MockQueue) Enqueue(ctx context.Context, queue string, payload []byte, opts ...gas.EnqueueOption) error
- func (m *MockQueue) Nack(ctx context.Context, queue string, job gas.Job) error
- func (m *MockQueue) Reset()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockQueue ¶
type MockQueue struct {
EnqueueFn func(ctx context.Context, queue string, payload []byte, opts ...gas.EnqueueOption) error
DequeueFn func(ctx context.Context, queue string, maxMessages int, wait time.Duration) ([]gas.Job, error)
AckFn func(ctx context.Context, queue string, job gas.Job) error
NackFn func(ctx context.Context, queue string, job gas.Job) error
Calls []Call
// contains filtered or unexported fields
}
MockQueue is a configurable mock of gas.JobQueueProvider. Each method delegates to its corresponding Fn field if set, otherwise returns the zero value. All calls are recorded in the Calls slice for assertions.
func (*MockQueue) Dequeue ¶
func (m *MockQueue) Dequeue( ctx context.Context, queue string, maxMessages int, wait time.Duration, ) ([]gas.Job, error)
Dequeue records the call and delegates to DequeueFn if set.
func (*MockQueue) Enqueue ¶
func (m *MockQueue) Enqueue( ctx context.Context, queue string, payload []byte, opts ...gas.EnqueueOption, ) error
Enqueue records the call and delegates to EnqueueFn if set.