(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func Test_RecordedOutput(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | ctx := context.Background() |
| 22 | |
| 23 | type JobArgs struct { |
| 24 | testutil.JobArgsReflectKind[JobArgs] |
| 25 | } |
| 26 | |
| 27 | type myOutput struct { |
| 28 | Message string `json:"message"` |
| 29 | } |
| 30 | |
| 31 | type testBundle struct { |
| 32 | dbPool *pgxpool.Pool |
| 33 | schema string |
| 34 | } |
| 35 | |
| 36 | setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) { |
| 37 | t.Helper() |
| 38 | |
| 39 | var ( |
| 40 | dbPool = riversharedtest.DBPool(ctx, t) |
| 41 | driver = riverpgxv5.New(dbPool) |
| 42 | schema = riverdbtest.TestSchema(ctx, t, driver, nil) |
| 43 | config = newTestConfig(t, schema) |
| 44 | client = newTestClient(t, dbPool, config) |
| 45 | ) |
| 46 | |
| 47 | t.Cleanup(func() { require.NoError(t, client.Stop(ctx)) }) |
| 48 | |
| 49 | return client, &testBundle{ |
| 50 | dbPool: dbPool, |
| 51 | schema: schema, |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | t.Run("ValidOutput", func(t *testing.T) { |
| 56 | t.Parallel() |
| 57 | |
| 58 | client, _ := setup(t) |
| 59 | |
| 60 | validOutput := myOutput{Message: "it worked"} |
| 61 | expectedOutput := `{"output":{"message":"it worked"}}` |
| 62 | AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error { |
| 63 | return RecordOutput(ctx, validOutput) |
| 64 | })) |
| 65 | |
| 66 | subChan := subscribe(t, client) |
| 67 | startClient(ctx, t, client) |
| 68 | |
| 69 | insertRes, err := client.Insert(ctx, JobArgs{}, nil) |
| 70 | require.NoError(t, err) |
| 71 | |
| 72 | event := riversharedtest.WaitOrTimeout(t, subChan) |
| 73 | require.Equal(t, EventKindJobCompleted, event.Kind) |
| 74 | require.JSONEq(t, expectedOutput, string(event.Job.Metadata)) |
| 75 | |
| 76 | jobFromDB, err := client.JobGet(ctx, insertRes.Job.ID) |
nothing calls this directly
no test coverage detected
searching dependent graphs…