queuefake

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package queuefake provides a queue-first test harness for queue and workflow assertions.

It wraps queue.NewFake() for dispatch assertions and bus.NewFake() for workflow orchestration assertions so tests can stay aligned with the flattened queue API surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake exposes a queue test harness with assertion helpers for dispatched jobs. It wraps queue.NewFake() so tests can inject a queue fake without external services. @group Testing

func New

func New() *Fake

New creates a fake queue harness backed by queue.NewFake(). @group Testing

Example: queuefake harness

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("emails:send").OnQueue("default"))
f.AssertDispatched(t, "emails:send")
f.AssertCount(t, 1)

func (*Fake) AssertBatchCount

func (f *Fake) AssertBatchCount(t testing.TB, n int)

AssertBatchCount fails if total recorded workflow batch count does not match n. @group Testing

Example: assert workflow batch count

f := queuefake.New()
_, _ = f.Workflow().Batch(bus.NewJob("a", nil)).Dispatch(nil)
f.AssertBatchCount(t, 1)

func (*Fake) AssertBatched

func (f *Fake) AssertBatched(t testing.TB, predicate func(spec bus.BatchSpec) bool)

AssertBatched fails unless at least one recorded workflow batch matches predicate. @group Testing

Example: assert batched jobs by predicate

f := queuefake.New()
_, _ = f.Workflow().Batch(bus.NewJob("a", nil), bus.NewJob("b", nil)).Dispatch(nil)
f.AssertBatched(t, func(spec bus.BatchSpec) bool { return len(spec.JobTypes) == 2 })

func (*Fake) AssertChained

func (f *Fake) AssertChained(t testing.TB, expected []string)

AssertChained fails if no recorded workflow chain matches expected job type order. @group Testing

Example: assert chain sequence

f := queuefake.New()
_, _ = f.Workflow().Chain(bus.NewJob("a", nil), bus.NewJob("b", nil)).Dispatch(nil)
f.AssertChained(t, []string{"a", "b"})

func (*Fake) AssertCount

func (f *Fake) AssertCount(t testing.TB, expected int)

AssertCount fails when total dispatch count is not expected. @group Testing

Example: assert total queue dispatch count

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("a"))
_ = q.Dispatch(queue.NewJob("b"))
f.AssertCount(t, 2)

func (*Fake) AssertDispatched

func (f *Fake) AssertDispatched(t testing.TB, jobType string)

AssertDispatched fails when jobType was not dispatched. @group Testing

Example: assert queue dispatch by type

f := queuefake.New()
_ = f.Queue().Dispatch(queue.NewJob("emails:send"))
f.AssertDispatched(t, "emails:send")

func (*Fake) AssertDispatchedOn

func (f *Fake) AssertDispatchedOn(t testing.TB, queueName, jobType string)

AssertDispatchedOn fails when jobType was not dispatched on queueName. @group Testing

Example: assert queue dispatch on queue

f := queuefake.New()
_ = f.Queue().Dispatch(queue.NewJob("emails:send").OnQueue("critical"))
f.AssertDispatchedOn(t, "critical", "emails:send")

func (*Fake) AssertDispatchedTimes

func (f *Fake) AssertDispatchedTimes(t testing.TB, jobType string, expected int)

AssertDispatchedTimes fails when jobType dispatch count does not match expected. @group Testing

Example: assert queue dispatch count by type

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("emails:send"))
_ = q.Dispatch(queue.NewJob("emails:send"))
f.AssertDispatchedTimes(t, "emails:send", 2)

func (*Fake) AssertNotDispatched

func (f *Fake) AssertNotDispatched(t testing.TB, jobType string)

AssertNotDispatched fails when jobType was dispatched. @group Testing

Example: assert queue type was not dispatched

f := queuefake.New()
f.AssertNotDispatched(t, "emails:send")

func (*Fake) AssertNothingBatched

func (f *Fake) AssertNothingBatched(t testing.TB)

AssertNothingBatched fails if any workflow batch was recorded. @group Testing

Example: assert no workflow batches

f := queuefake.New()
f.AssertNothingBatched(t)

func (*Fake) AssertNothingDispatched

func (f *Fake) AssertNothingDispatched(t testing.TB)

AssertNothingDispatched fails when any dispatch was recorded. @group Testing

Example: assert no queue dispatches

f := queuefake.New()
f.AssertNothingDispatched(t)

func (*Fake) AssertNothingWorkflowDispatched

func (f *Fake) AssertNothingWorkflowDispatched(t testing.TB)

AssertNothingWorkflowDispatched fails when any workflow dispatch was recorded. @group Testing

Example: assert no workflow dispatches

f := queuefake.New()
f.AssertNothingWorkflowDispatched(t)

func (*Fake) AssertWorkflowDispatched

func (f *Fake) AssertWorkflowDispatched(t testing.TB, jobType string)

AssertWorkflowDispatched fails when jobType was not workflow-dispatched. @group Testing

Example: assert workflow dispatch by type

f := queuefake.New()
_, _ = f.Workflow().Chain(bus.NewJob("a", nil)).Dispatch(nil)
f.AssertWorkflowDispatched(t, "a")

func (*Fake) AssertWorkflowDispatchedOn

func (f *Fake) AssertWorkflowDispatchedOn(t testing.TB, queueName, jobType string)

AssertWorkflowDispatchedOn fails when jobType was not workflow-dispatched on queueName. @group Testing

Example: assert workflow dispatch on queue

f := queuefake.New()
_, _ = f.Workflow().Chain(bus.NewJob("a", nil)).OnQueue("critical").Dispatch(nil)
f.AssertWorkflowDispatchedOn(t, "critical", "a")

func (*Fake) AssertWorkflowDispatchedTimes

func (f *Fake) AssertWorkflowDispatchedTimes(t testing.TB, jobType string, expected int)

AssertWorkflowDispatchedTimes fails when workflow dispatch count for jobType does not match expected. @group Testing

Example: assert workflow dispatch count

f := queuefake.New()
wf := f.Workflow()
_, _ = wf.Chain(bus.NewJob("a", nil)).Dispatch(nil)
_, _ = wf.Chain(bus.NewJob("a", nil)).Dispatch(nil)
f.AssertWorkflowDispatchedTimes(t, "a", 2)

func (*Fake) AssertWorkflowNotDispatched

func (f *Fake) AssertWorkflowNotDispatched(t testing.TB, jobType string)

AssertWorkflowNotDispatched fails when jobType was workflow-dispatched. @group Testing

Example: assert workflow not dispatched

f := queuefake.New()
f.AssertWorkflowNotDispatched(t, "emails:send")

func (*Fake) Count

func (f *Fake) Count() int

Count returns the total number of recorded dispatches. @group Testing

Example: count total dispatches

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("a"))
_ = q.Dispatch(queue.NewJob("b"))
_ = f.Count()

func (*Fake) CountJob

func (f *Fake) CountJob(jobType string) int

CountJob returns how many times a job type was dispatched. @group Testing

Example: count by job type

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("emails:send"))
_ = q.Dispatch(queue.NewJob("emails:send"))
_ = f.CountJob("emails:send")

func (*Fake) CountOn

func (f *Fake) CountOn(queueName, jobType string) int

CountOn returns how many times a job type was dispatched on a queue. @group Testing

Example: count by queue and job type

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("emails:send").OnQueue("critical"))
_ = f.CountOn("critical", "emails:send")

func (*Fake) Queue

func (f *Fake) Queue() *queue.FakeQueue

Queue returns the queue fake to inject into code under test. @group Testing

Example: queue fake

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("emails:send").OnQueue("default"))

func (*Fake) Records

func (f *Fake) Records() []queue.DispatchRecord

Records returns a copy of recorded dispatches. @group Testing

Example: inspect recorded dispatches

f := queuefake.New()
_ = f.Queue().Dispatch(queue.NewJob("emails:send"))
records := f.Records()
_ = records

func (*Fake) Reset

func (f *Fake) Reset()

Reset clears recorded dispatches. @group Testing

Example: reset recorded dispatches

f := queuefake.New()
q := f.Queue()
_ = q.Dispatch(queue.NewJob("emails:send"))
f.Reset()
f.AssertNothingDispatched(t)

func (*Fake) Workflow

func (f *Fake) Workflow() *bus.Fake

Workflow returns the workflow/orchestration fake for chain/batch assertions. @group Testing

Example: workflow fake

f := queuefake.New()
wf := f.Workflow()
_, _ = wf.Chain(
	bus.NewJob("a", nil),
	bus.NewJob("b", nil),
).Dispatch(context.Background())
f.AssertChained(t, []string{"a", "b"})

Jump to

Keyboard shortcuts

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