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 ¶
- type Fake
- func (f *Fake) AssertBatchCount(t testing.TB, n int)
- func (f *Fake) AssertBatched(t testing.TB, predicate func(spec bus.BatchSpec) bool)
- func (f *Fake) AssertChained(t testing.TB, expected []string)
- func (f *Fake) AssertCount(t testing.TB, expected int)
- func (f *Fake) AssertDispatched(t testing.TB, jobType string)
- func (f *Fake) AssertDispatchedOn(t testing.TB, queueName, jobType string)
- func (f *Fake) AssertDispatchedTimes(t testing.TB, jobType string, expected int)
- func (f *Fake) AssertNotDispatched(t testing.TB, jobType string)
- func (f *Fake) AssertNothingBatched(t testing.TB)
- func (f *Fake) AssertNothingDispatched(t testing.TB)
- func (f *Fake) AssertNothingWorkflowDispatched(t testing.TB)
- func (f *Fake) AssertWorkflowDispatched(t testing.TB, jobType string)
- func (f *Fake) AssertWorkflowDispatchedOn(t testing.TB, queueName, jobType string)
- func (f *Fake) AssertWorkflowDispatchedTimes(t testing.TB, jobType string, expected int)
- func (f *Fake) AssertWorkflowNotDispatched(t testing.TB, jobType string)
- func (f *Fake) Count() int
- func (f *Fake) CountJob(jobType string) int
- func (f *Fake) CountOn(queueName, jobType string) int
- func (f *Fake) Queue() *queue.FakeQueue
- func (f *Fake) Records() []queue.DispatchRecord
- func (f *Fake) Reset()
- func (f *Fake) Workflow() *bus.Fake
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
AssertNothingBatched fails if any workflow batch was recorded. @group Testing
Example: assert no workflow batches
f := queuefake.New() f.AssertNothingBatched(t)
func (*Fake) AssertNothingDispatched ¶
AssertNothingDispatched fails when any dispatch was recorded. @group Testing
Example: assert no queue dispatches
f := queuefake.New() f.AssertNothingDispatched(t)
func (*Fake) AssertNothingWorkflowDispatched ¶
AssertNothingWorkflowDispatched fails when any workflow dispatch was recorded. @group Testing
Example: assert no workflow dispatches
f := queuefake.New() f.AssertNothingWorkflowDispatched(t)
func (*Fake) AssertWorkflowDispatched ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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"})