nolint:gochecknoglobals
(t *testing.T)
| 27 | var firstInvocationOpts = &TestSchemaOpts{skipPackageNameCheck: true} //nolint:gochecknoglobals |
| 28 | |
| 29 | func TestTestSchema(t *testing.T) { |
| 30 | t.Parallel() |
| 31 | |
| 32 | var ( |
| 33 | ctx = context.Background() |
| 34 | dbPool = riversharedtest.DBPool(ctx, t) |
| 35 | driver = riverpgxv5.New(dbPool) |
| 36 | exec = driver.GetExecutor() |
| 37 | ) |
| 38 | |
| 39 | t.Run("BasicExerciseAndVisibility", func(t *testing.T) { |
| 40 | t.Parallel() |
| 41 | |
| 42 | schema1 := TestSchema(ctx, t, driver, firstInvocationOpts) |
| 43 | require.Regexp(t, `\Ariverdbtest_`, schema1) |
| 44 | |
| 45 | schema2 := TestSchema(ctx, t, driver, nil) |
| 46 | require.Regexp(t, `\Ariverdbtest_`, schema2) |
| 47 | |
| 48 | require.NotEqual(t, schema1, schema2) |
| 49 | |
| 50 | job1 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{Kind: ptrutil.Ptr("schema1_job"), Schema: schema1}) |
| 51 | job2 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{Kind: ptrutil.Ptr("schema2_job"), Schema: schema2}) |
| 52 | |
| 53 | // Each job is found in its appropriate schema. Make sure to check kind |
| 54 | // because for many test runs IDs will be identical across schemas |
| 55 | // because both schemas are brand new and start at 1. (Although they may |
| 56 | // diverge depending on which tests get run first, and will certainly |
| 57 | // diverge with higher iteration counts with `go test -count`.) |
| 58 | { |
| 59 | fetchedJob1, err := exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job1.ID, Schema: schema1}) |
| 60 | require.NoError(t, err) |
| 61 | require.Equal(t, "schema1_job", fetchedJob1.Kind) |
| 62 | |
| 63 | fetchedJob2, err := exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job2.ID, Schema: schema2}) |
| 64 | require.NoError(t, err) |
| 65 | require.Equal(t, "schema2_job", fetchedJob2.Kind) |
| 66 | } |
| 67 | |
| 68 | // Essentially the same check as above, but just looking that jobs are |
| 69 | // found in each schema by their appropriate kind. |
| 70 | { |
| 71 | fetchedJobs1, err := exec.JobGetByKindMany(ctx, &riverdriver.JobGetByKindManyParams{Kind: []string{"schema1_job"}, Schema: schema1}) |
| 72 | require.NoError(t, err) |
| 73 | require.Len(t, fetchedJobs1, 1) |
| 74 | |
| 75 | fetchedJobs2, err := exec.JobGetByKindMany(ctx, &riverdriver.JobGetByKindManyParams{Kind: []string{"schema2_job"}, Schema: schema2}) |
| 76 | require.NoError(t, err) |
| 77 | require.Len(t, fetchedJobs2, 1) |
| 78 | } |
| 79 | |
| 80 | // Invert the schemas on each check to show that no jobs intended for |
| 81 | // the other schema are found in each other's schema. |
| 82 | { |
| 83 | fetchedJobs1, err := exec.JobGetByKindMany(ctx, &riverdriver.JobGetByKindManyParams{Kind: []string{"schema1_job"}, Schema: schema2}) |
| 84 | require.NoError(t, err) |
| 85 | require.Empty(t, fetchedJobs1) |
| 86 |
nothing calls this directly
no test coverage detected
searching dependent graphs…