You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow explicit schema injection to rivertest.Require* test functions (#926)
Here, resolve#907 by letting an explicit schema be injected into
`rivertest.Require*` assertions in a similar way that one can be used in
a client.
This approach adds a schema in `RequireInsertedOpts`. This comment does
a good job of highlight all the potential approaches for adding a schema
[1], and unfortunately none of them are all that great. I implemented
one other version of this (a variant of option 2 in that list), which as
some advantages, but in the end it just ended up ballooning the API out
to an uncomfortable degree.
The worst part about adding schema to `RequireInsertedOpts` is its
interact with the `RequireMany*` functions, where each expectation can
set its own schema, and it's not clear what would happen if different
expectations set different schemas. I resolved this ambiguity by making
it an error to mix and match schemas. Assertions are allowed to send a
schema in only the first position like:
jobs := requireManyInserted(ctx, bundle.mockT, bundle.driver, []ExpectedJob{
{Args: &Job1Args{String: "foo"}, Opts: bundle.schemaOpts},
{Args: &Job1Args{String: "bar"}},
})
Or send the same schema in all positions:
jobs := requireManyInserted(ctx, bundle.mockT, bundle.driver, []ExpectedJob{
{Args: &Job1Args{String: "foo"}, Opts: bundle.schemaOpts},
{Args: &Job1Args{String: "bar"}, Opts: bundle.schemaOpts},
})
But they aren't allowed to set a schema only in position other than the
first, or mix and match schemas between expectations.
Fixes#907.
[1] #907 (comment)
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
- Preliminary River driver for SQLite (`riverdriver/riversqlite`). This driver seems to produce good results as judged by the test suite, but so far has minimal real world vetting. Try it and let us know how it works out. [PR #870](https://github.com/riverqueue/river/pull/870).
15
15
- CLI `river migrate-get` now takes a `--schema` option to inject a custom schema into dumped migrations and schema comments are hidden if `--schema` option isn't provided. [PR #903](https://github.com/riverqueue/river/pull/903).
16
16
- Added `riverlog.NewMiddlewareCustomContext` that makes the use of `riverlog` job-persisted logging possible with non-slog loggers. [PR #919](https://github.com/riverqueue/river/pull/919).
17
+
- Added `RequireInsertedOpts.Schema`, allowing an explicit schema to be set when asserting on job inserts with `rivertest`. [PR #926](https://github.com/riverqueue/river/pull/926).
18
+
- Added `JobListParams.Where`, which provides an escape hatch for job listing that runs arbitrary SQL with named parameters. [PR #933](https://github.com/riverqueue/river/pull/933).
0 commit comments