ExerciseClient exercises a client using a generic driver using a minimal set of test cases to verify that the driver works end to end.
(ctx context.Context, t *testing.T, driverWithSchema func(ctx context.Context, t *testing.T) (riverdriver.Driver[TTx], string), )
| 200 | // ExerciseClient exercises a client using a generic driver using a minimal set |
| 201 | // of test cases to verify that the driver works end to end. |
| 202 | func ExerciseClient[TTx any](ctx context.Context, t *testing.T, |
| 203 | driverWithSchema func(ctx context.Context, t *testing.T) (riverdriver.Driver[TTx], string), |
| 204 | ) { |
| 205 | t.Helper() |
| 206 | |
| 207 | type testBundle struct { |
| 208 | config *river.Config |
| 209 | driver riverdriver.Driver[TTx] |
| 210 | exec riverdriver.Executor |
| 211 | schema string |
| 212 | } |
| 213 | |
| 214 | // Alternate setup returning only client Config rather than a full Client. |
| 215 | setupConfig := func(t *testing.T) (*river.Config, *testBundle) { |
| 216 | t.Helper() |
| 217 | |
| 218 | var ( |
| 219 | driver, schema = driverWithSchema(ctx, t) |
| 220 | config = newTestConfig(t, schema) |
| 221 | ) |
| 222 | |
| 223 | return config, &testBundle{ |
| 224 | config: config, |
| 225 | driver: driver, |
| 226 | exec: driver.GetExecutor(), |
| 227 | schema: schema, |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | setup := func(t *testing.T) (*river.Client[TTx], *testBundle) { |
| 232 | t.Helper() |
| 233 | |
| 234 | config, bundle := setupConfig(t) |
| 235 | |
| 236 | client, err := river.NewClient(bundle.driver, config) |
| 237 | require.NoError(t, err) |
| 238 | |
| 239 | return client, bundle |
| 240 | } |
| 241 | |
| 242 | beginTx := func(ctx context.Context, t *testing.T, bundle *testBundle) (TTx, riverdriver.ExecutorTx) { |
| 243 | t.Helper() |
| 244 | |
| 245 | execTx, err := bundle.driver.GetExecutor().Begin(ctx) |
| 246 | require.NoError(t, err) |
| 247 | |
| 248 | // Ignore error on cleanup so we can roll back early in tests where desirable. |
| 249 | t.Cleanup(func() { _ = execTx.Rollback(ctx) }) |
| 250 | |
| 251 | return bundle.driver.UnwrapTx(execTx), execTx |
| 252 | } |
| 253 | |
| 254 | t.Run("StartInsertAndWork", func(t *testing.T) { |
| 255 | t.Parallel() |
| 256 | |
| 257 | client, bundle := setup(t) |
| 258 | |
| 259 | type JobArgs struct { |
no test coverage detected
searching dependent graphs…