Skip to content

Commit 4d1fbb2

Browse files
committed
chore: fake example adjustments
1 parent 7345111 commit 4d1fbb2

File tree

7 files changed

+59
-54
lines changed

7 files changed

+59
-54
lines changed

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ AssertCount fails when dispatch count is not expected.
14171417
```go
14181418
fake := queue.NewFake()
14191419
_ = fake.Dispatch(queue.NewJob("emails:send"))
1420-
fake.AssertCount(nil, 1)
1420+
fake.AssertCount(t, 1)
14211421
```
14221422

14231423
#### <a id="queue-fakequeue-assertdispatched"></a>FakeQueue.AssertDispatched
@@ -1427,7 +1427,7 @@ AssertDispatched fails when jobType was not dispatched.
14271427
```go
14281428
fake := queue.NewFake()
14291429
_ = fake.Dispatch(queue.NewJob("emails:send"))
1430-
fake.AssertDispatched(nil, "emails:send")
1430+
fake.AssertDispatched(t, "emails:send")
14311431
```
14321432

14331433
#### <a id="queue-fakequeue-assertdispatchedon"></a>FakeQueue.AssertDispatchedOn
@@ -1440,7 +1440,7 @@ _ = fake.Dispatch(
14401440
queue.NewJob("emails:send").
14411441
OnQueue("critical"),
14421442
)
1443-
fake.AssertDispatchedOn(nil, "critical", "emails:send")
1443+
fake.AssertDispatchedOn(t, "critical", "emails:send")
14441444
```
14451445

14461446
#### <a id="queue-fakequeue-assertdispatchedtimes"></a>FakeQueue.AssertDispatchedTimes
@@ -1451,7 +1451,7 @@ AssertDispatchedTimes fails when jobType dispatch count does not match expected.
14511451
fake := queue.NewFake()
14521452
_ = fake.Dispatch(queue.NewJob("emails:send"))
14531453
_ = fake.Dispatch(queue.NewJob("emails:send"))
1454-
fake.AssertDispatchedTimes(nil, "emails:send", 2)
1454+
fake.AssertDispatchedTimes(t, "emails:send", 2)
14551455
```
14561456

14571457
#### <a id="queue-fakequeue-assertnotdispatched"></a>FakeQueue.AssertNotDispatched
@@ -1461,7 +1461,7 @@ AssertNotDispatched fails when jobType was dispatched.
14611461
```go
14621462
fake := queue.NewFake()
14631463
_ = fake.Dispatch(queue.NewJob("emails:send"))
1464-
fake.AssertNotDispatched(nil, "emails:cancel")
1464+
fake.AssertNotDispatched(t, "emails:cancel")
14651465
```
14661466

14671467
#### <a id="queue-fakequeue-assertnothingdispatched"></a>FakeQueue.AssertNothingDispatched
@@ -1470,7 +1470,7 @@ AssertNothingDispatched fails when any dispatch was recorded.
14701470

14711471
```go
14721472
fake := queue.NewFake()
1473-
fake.AssertNothingDispatched(nil)
1473+
fake.AssertNothingDispatched(t)
14741474
```
14751475

14761476
#### <a id="queue-fakequeue-dispatch"></a>FakeQueue.Dispatch
@@ -1862,14 +1862,16 @@ if err != nil {
18621862

18631863
## Testing API
18641864

1865+
Examples in this section assume they are used inside tests and `t` is a `*testing.T` (or `testing.TB`).
1866+
18651867
#### <a id="queuefake-fake-assertbatchcount"></a>Fake.AssertBatchCount
18661868

18671869
AssertBatchCount fails if total recorded workflow batch count does not match n.
18681870

18691871
```go
18701872
f := queuefake.New()
18711873
_, _ = f.Workflow().Batch(bus.NewJob("a", nil)).Dispatch(nil)
1872-
f.AssertBatchCount(nil, 1)
1874+
f.AssertBatchCount(t, 1)
18731875
```
18741876

18751877
#### <a id="queuefake-fake-assertbatched"></a>Fake.AssertBatched
@@ -1879,7 +1881,7 @@ AssertBatched fails unless at least one recorded workflow batch matches predicat
18791881
```go
18801882
f := queuefake.New()
18811883
_, _ = f.Workflow().Batch(bus.NewJob("a", nil), bus.NewJob("b", nil)).Dispatch(nil)
1882-
f.AssertBatched(nil, func(spec bus.BatchSpec) bool { return len(spec.Jobs) == 2 })
1884+
f.AssertBatched(t, func(spec bus.BatchSpec) bool { return len(spec.JobTypes) == 2 })
18831885
```
18841886

18851887
#### <a id="queuefake-fake-assertchained"></a>Fake.AssertChained
@@ -1889,7 +1891,7 @@ AssertChained fails if no recorded workflow chain matches expected job type orde
18891891
```go
18901892
f := queuefake.New()
18911893
_, _ = f.Workflow().Chain(bus.NewJob("a", nil), bus.NewJob("b", nil)).Dispatch(nil)
1892-
f.AssertChained(nil, []string{"a", "b"})
1894+
f.AssertChained(t, []string{"a", "b"})
18931895
```
18941896

18951897
#### <a id="queuefake-fake-assertcount"></a>Fake.AssertCount
@@ -1901,7 +1903,7 @@ f := queuefake.New()
19011903
q := f.Queue()
19021904
_ = q.Dispatch(queue.NewJob("a"))
19031905
_ = q.Dispatch(queue.NewJob("b"))
1904-
f.AssertCount(nil, 2)
1906+
f.AssertCount(t, 2)
19051907
```
19061908

19071909
#### <a id="queuefake-fake-assertdispatched"></a>Fake.AssertDispatched
@@ -1911,7 +1913,7 @@ AssertDispatched fails when jobType was not dispatched.
19111913
```go
19121914
f := queuefake.New()
19131915
_ = f.Queue().Dispatch(queue.NewJob("emails:send"))
1914-
f.AssertDispatched(nil, "emails:send")
1916+
f.AssertDispatched(t, "emails:send")
19151917
```
19161918

19171919
#### <a id="queuefake-fake-assertdispatchedon"></a>Fake.AssertDispatchedOn
@@ -1921,7 +1923,7 @@ AssertDispatchedOn fails when jobType was not dispatched on queueName.
19211923
```go
19221924
f := queuefake.New()
19231925
_ = f.Queue().Dispatch(queue.NewJob("emails:send").OnQueue("critical"))
1924-
f.AssertDispatchedOn(nil, "critical", "emails:send")
1926+
f.AssertDispatchedOn(t, "critical", "emails:send")
19251927
```
19261928

19271929
#### <a id="queuefake-fake-assertdispatchedtimes"></a>Fake.AssertDispatchedTimes
@@ -1933,7 +1935,7 @@ f := queuefake.New()
19331935
q := f.Queue()
19341936
_ = q.Dispatch(queue.NewJob("emails:send"))
19351937
_ = q.Dispatch(queue.NewJob("emails:send"))
1936-
f.AssertDispatchedTimes(nil, "emails:send", 2)
1938+
f.AssertDispatchedTimes(t, "emails:send", 2)
19371939
```
19381940

19391941
#### <a id="queuefake-fake-assertnotdispatched"></a>Fake.AssertNotDispatched
@@ -1942,7 +1944,7 @@ AssertNotDispatched fails when jobType was dispatched.
19421944

19431945
```go
19441946
f := queuefake.New()
1945-
f.AssertNotDispatched(nil, "emails:send")
1947+
f.AssertNotDispatched(t, "emails:send")
19461948
```
19471949

19481950
#### <a id="queuefake-fake-assertnothingbatched"></a>Fake.AssertNothingBatched
@@ -1951,7 +1953,7 @@ AssertNothingBatched fails if any workflow batch was recorded.
19511953

19521954
```go
19531955
f := queuefake.New()
1954-
f.AssertNothingBatched(nil)
1956+
f.AssertNothingBatched(t)
19551957
```
19561958

19571959
#### <a id="queuefake-fake-assertnothingdispatched"></a>Fake.AssertNothingDispatched
@@ -1960,7 +1962,7 @@ AssertNothingDispatched fails when any dispatch was recorded.
19601962

19611963
```go
19621964
f := queuefake.New()
1963-
f.AssertNothingDispatched(nil)
1965+
f.AssertNothingDispatched(t)
19641966
```
19651967

19661968
#### <a id="queuefake-fake-assertnothingworkflowdispatched"></a>Fake.AssertNothingWorkflowDispatched
@@ -1969,7 +1971,7 @@ AssertNothingWorkflowDispatched fails when any workflow dispatch was recorded.
19691971

19701972
```go
19711973
f := queuefake.New()
1972-
f.AssertNothingWorkflowDispatched(nil)
1974+
f.AssertNothingWorkflowDispatched(t)
19731975
```
19741976

19751977
#### <a id="queuefake-fake-assertworkflowdispatched"></a>Fake.AssertWorkflowDispatched
@@ -1979,7 +1981,7 @@ AssertWorkflowDispatched fails when jobType was not workflow-dispatched.
19791981
```go
19801982
f := queuefake.New()
19811983
_, _ = f.Workflow().Chain(bus.NewJob("a", nil)).Dispatch(nil)
1982-
f.AssertWorkflowDispatched(nil, "a")
1984+
f.AssertWorkflowDispatched(t, "a")
19831985
```
19841986

19851987
#### <a id="queuefake-fake-assertworkflowdispatchedon"></a>Fake.AssertWorkflowDispatchedOn
@@ -1989,7 +1991,7 @@ AssertWorkflowDispatchedOn fails when jobType was not workflow-dispatched on que
19891991
```go
19901992
f := queuefake.New()
19911993
_, _ = f.Workflow().Chain(bus.NewJob("a", nil)).OnQueue("critical").Dispatch(nil)
1992-
f.AssertWorkflowDispatchedOn(nil, "critical", "a")
1994+
f.AssertWorkflowDispatchedOn(t, "critical", "a")
19931995
```
19941996

19951997
#### <a id="queuefake-fake-assertworkflowdispatchedtimes"></a>Fake.AssertWorkflowDispatchedTimes
@@ -2001,7 +2003,7 @@ f := queuefake.New()
20012003
wf := f.Workflow()
20022004
_, _ = wf.Chain(bus.NewJob("a", nil)).Dispatch(nil)
20032005
_, _ = wf.Chain(bus.NewJob("a", nil)).Dispatch(nil)
2004-
f.AssertWorkflowDispatchedTimes(nil, "a", 2)
2006+
f.AssertWorkflowDispatchedTimes(t, "a", 2)
20052007
```
20062008

20072009
#### <a id="queuefake-fake-assertworkflownotdispatched"></a>Fake.AssertWorkflowNotDispatched
@@ -2010,7 +2012,7 @@ AssertWorkflowNotDispatched fails when jobType was workflow-dispatched.
20102012

20112013
```go
20122014
f := queuefake.New()
2013-
f.AssertWorkflowNotDispatched(nil, "emails:send")
2015+
f.AssertWorkflowNotDispatched(t, "emails:send")
20142016
```
20152017

20162018
#### <a id="queuefake-fake-count"></a>Fake.Count
@@ -2056,8 +2058,8 @@ New creates a fake queue harness backed by queue.NewFake().
20562058
f := queuefake.New()
20572059
q := f.Queue()
20582060
_ = q.Dispatch(queue.NewJob("emails:send").OnQueue("default"))
2059-
f.AssertDispatched(nil, "emails:send")
2060-
f.AssertCount(nil, 1)
2061+
f.AssertDispatched(t, "emails:send")
2062+
f.AssertCount(t, 1)
20612063
```
20622064

20632065
#### <a id="queuefake-fake-queue"></a>Fake.Queue
@@ -2089,7 +2091,7 @@ f := queuefake.New()
20892091
q := f.Queue()
20902092
_ = q.Dispatch(queue.NewJob("emails:send"))
20912093
f.Reset()
2092-
f.AssertNothingDispatched(nil)
2094+
f.AssertNothingDispatched(t)
20932095
```
20942096

20952097
#### <a id="queuefake-fake-workflow"></a>Fake.Workflow
@@ -2103,7 +2105,7 @@ _, _ = wf.Chain(
21032105
bus.NewJob("a", nil),
21042106
bus.NewJob("b", nil),
21052107
).Dispatch(context.Background())
2106-
f.AssertChained(nil, []string{"a", "b"})
2108+
f.AssertChained(t, []string{"a", "b"})
21072109
```
21082110
<!-- api:embed:end -->
21092111

docs/readme/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ func renderAPI(funcs []*FuncDoc) string {
662662
buf.WriteString("## Driver Constructors\n\n")
663663
} else {
664664
buf.WriteString("## " + category + " API\n\n")
665+
if category == "Testing" {
666+
buf.WriteString("Examples in this section assume they are used inside tests and `t` is a `*testing.T` (or `testing.TB`).\n\n")
667+
}
665668
}
666669
packages := make([]string, 0, len(byCategoryPackageGroup[category]))
667670
for p := range byCategoryPackageGroup[category] {

examples/queuefake-fake-reset/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ func main() {
1818
q := f.Queue()
1919
_ = q.Dispatch(queue.NewJob("emails:send"))
2020
f.Reset()
21-
f.AssertNothingDispatched(nil)
21+
f.AssertNothingDispatched(t)
2222
}

examples/queuefake-fake-workflow/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ func main() {
2121
bus.NewJob("a", nil),
2222
bus.NewJob("b", nil),
2323
).Dispatch(context.Background())
24-
f.AssertChained(nil, []string{"a", "b"})
24+
f.AssertChained(t, []string{"a", "b"})
2525
}

examples/queuefake-new/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ func main() {
1717
f := queuefake.New()
1818
q := f.Queue()
1919
_ = q.Dispatch(queue.NewJob("emails:send").OnQueue("default"))
20-
f.AssertDispatched(nil, "emails:send")
21-
f.AssertCount(nil, 1)
20+
f.AssertDispatched(t, "emails:send")
21+
f.AssertCount(t, 1)
2222
}

fake_queue.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (f *FakeQueue) Records() []DispatchRecord {
215215
// Example: assert nothing dispatched
216216
//
217217
// fake := queue.NewFake()
218-
// fake.AssertNothingDispatched(nil)
218+
// fake.AssertNothingDispatched(t)
219219
func (f *FakeQueue) AssertNothingDispatched(t testing.TB) {
220220
t.Helper()
221221
if got := len(f.Records()); got != 0 {
@@ -230,7 +230,7 @@ func (f *FakeQueue) AssertNothingDispatched(t testing.TB) {
230230
//
231231
// fake := queue.NewFake()
232232
// _ = fake.Dispatch(queue.NewJob("emails:send"))
233-
// fake.AssertCount(nil, 1)
233+
// fake.AssertCount(t, 1)
234234
func (f *FakeQueue) AssertCount(t testing.TB, expected int) {
235235
t.Helper()
236236
if got := len(f.Records()); got != expected {
@@ -245,7 +245,7 @@ func (f *FakeQueue) AssertCount(t testing.TB, expected int) {
245245
//
246246
// fake := queue.NewFake()
247247
// _ = fake.Dispatch(queue.NewJob("emails:send"))
248-
// fake.AssertDispatched(nil, "emails:send")
248+
// fake.AssertDispatched(t, "emails:send")
249249
func (f *FakeQueue) AssertDispatched(t testing.TB, jobType string) {
250250
t.Helper()
251251
for _, record := range f.Records() {
@@ -266,7 +266,7 @@ func (f *FakeQueue) AssertDispatched(t testing.TB, jobType string) {
266266
// queue.NewJob("emails:send").
267267
// OnQueue("critical"),
268268
// )
269-
// fake.AssertDispatchedOn(nil, "critical", "emails:send")
269+
// fake.AssertDispatchedOn(t, "critical", "emails:send")
270270
func (f *FakeQueue) AssertDispatchedOn(t testing.TB, queueName, jobType string) {
271271
t.Helper()
272272
for _, record := range f.Records() {
@@ -285,7 +285,7 @@ func (f *FakeQueue) AssertDispatchedOn(t testing.TB, queueName, jobType string)
285285
// fake := queue.NewFake()
286286
// _ = fake.Dispatch(queue.NewJob("emails:send"))
287287
// _ = fake.Dispatch(queue.NewJob("emails:send"))
288-
// fake.AssertDispatchedTimes(nil, "emails:send", 2)
288+
// fake.AssertDispatchedTimes(t, "emails:send", 2)
289289
func (f *FakeQueue) AssertDispatchedTimes(t testing.TB, jobType string, expected int) {
290290
t.Helper()
291291
var count int
@@ -306,7 +306,7 @@ func (f *FakeQueue) AssertDispatchedTimes(t testing.TB, jobType string, expected
306306
//
307307
// fake := queue.NewFake()
308308
// _ = fake.Dispatch(queue.NewJob("emails:send"))
309-
// fake.AssertNotDispatched(nil, "emails:cancel")
309+
// fake.AssertNotDispatched(t, "emails:cancel")
310310
func (f *FakeQueue) AssertNotDispatched(t testing.TB, jobType string) {
311311
t.Helper()
312312
for _, record := range f.Records() {

0 commit comments

Comments
 (0)