riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.51k stars 94 forks source link

Add `rivertest.WorkContext` for use testing `JobArgs.Work` implementations #526

Closed brandur closed 2 months ago

brandur commented 2 months ago

Here, add a new test helper called rivertest.WorkContext. Its purpose is to generate a realistic looking context for testing JobArgs.Work implementation, particularly by adding a client to context that makes river.ClientFromContext available in tests, but may also be used to add any other context-related features that may be added in the future.

We've talked about new test helpers for running Work implementations and may still do that, but this is a primitive that makes testing a little better without having to add anything heavyweight.

Fixes #512.