queuetest

package
v0.5.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Method string
	Args   []any
}

Call records a single method invocation on the mock.

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) Ack

func (m *MockQueue) Ack(ctx context.Context, queue string, job gas.Job) error

Ack records the call and delegates to AckFn if set.

func (*MockQueue) CallCount

func (m *MockQueue) CallCount(method string) int

CallCount returns the number of times the given method was called.

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.

func (*MockQueue) Nack

func (m *MockQueue) Nack(ctx context.Context, queue string, job gas.Job) error

Nack records the call and delegates to NackFn if set.

func (*MockQueue) Reset

func (m *MockQueue) Reset()

Reset clears all recorded calls.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL