(t *testing.T)
| 5375 | } |
| 5376 | |
| 5377 | func Test_Client_JobUpdateTx(t *testing.T) { |
| 5378 | t.Parallel() |
| 5379 | |
| 5380 | ctx := context.Background() |
| 5381 | |
| 5382 | type testBundle struct { |
| 5383 | dbPool *pgxpool.Pool |
| 5384 | executorTx riverdriver.ExecutorTx |
| 5385 | tx pgx.Tx |
| 5386 | } |
| 5387 | |
| 5388 | setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) { |
| 5389 | t.Helper() |
| 5390 | |
| 5391 | var ( |
| 5392 | dbPool = riversharedtest.DBPool(ctx, t) |
| 5393 | driver = riverpgxv5.New(dbPool) |
| 5394 | schema = riverdbtest.TestSchema(ctx, t, driver, nil) |
| 5395 | config = newTestConfig(t, schema) |
| 5396 | client = newTestClient(t, dbPool, config) |
| 5397 | ) |
| 5398 | |
| 5399 | tx, err := dbPool.Begin(ctx) |
| 5400 | require.NoError(t, err) |
| 5401 | t.Cleanup(func() { tx.Rollback(ctx) }) |
| 5402 | |
| 5403 | return client, &testBundle{ |
| 5404 | dbPool: dbPool, |
| 5405 | executorTx: client.driver.UnwrapExecutor(tx), |
| 5406 | tx: tx, |
| 5407 | } |
| 5408 | } |
| 5409 | |
| 5410 | t.Run("AllParams", func(t *testing.T) { |
| 5411 | t.Parallel() |
| 5412 | |
| 5413 | client, bundle := setup(t) |
| 5414 | |
| 5415 | insertRes, err := client.Insert(ctx, noOpArgs{}, &InsertOpts{}) |
| 5416 | require.NoError(t, err) |
| 5417 | |
| 5418 | job, err := client.JobUpdateTx(ctx, bundle.tx, insertRes.Job.ID, &JobUpdateParams{ |
| 5419 | Output: "my job output", |
| 5420 | }) |
| 5421 | require.NoError(t, err) |
| 5422 | require.Equal(t, `"my job output"`, string(job.Output())) |
| 5423 | |
| 5424 | updatedJob, err := client.JobGetTx(ctx, bundle.tx, job.ID) |
| 5425 | require.NoError(t, err) |
| 5426 | require.Equal(t, `"my job output"`, string(updatedJob.Output())) |
| 5427 | |
| 5428 | // Outside of transaction shows original |
| 5429 | updatedJob, err = client.JobGet(ctx, job.ID) |
| 5430 | require.NoError(t, err) |
| 5431 | require.Empty(t, string(updatedJob.Output())) |
| 5432 | }) |
| 5433 | |
| 5434 | t.Run("NoParams", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…