(ctx context.Context, t testingT, exec riverdriver.Executor, expectedJobs []ExpectedJob)
| 402 | } |
| 403 | |
| 404 | func requireManyInsertedErr[TDriver riverdriver.Driver[TTx], TTx any](ctx context.Context, t testingT, exec riverdriver.Executor, expectedJobs []ExpectedJob) ([]*rivertype.JobRow, error) { |
| 405 | t.Helper() |
| 406 | |
| 407 | expectedArgsKinds := sliceutil.Map(expectedJobs, func(j ExpectedJob) string { return j.Args.Kind() }) |
| 408 | |
| 409 | var schema string |
| 410 | if len(expectedJobs) > 0 && expectedJobs[0].Opts != nil { |
| 411 | schema = expectedJobs[0].Opts.Schema |
| 412 | } |
| 413 | |
| 414 | // For simplicity (and because I can't think of any reason anyone would need |
| 415 | // to do otherwise), require that if an explicit schema is being set that |
| 416 | // it's the same explicit schema for all options. Callers may specify the |
| 417 | // schema only once in the first expectation's options, or specify the same |
| 418 | // schema for all expectations' options, but they're not allowed to set a |
| 419 | // schema after the first expectation's options if it wasn't set in the |
| 420 | // first, and not allowed to mix and match schemas between options. |
| 421 | for i, expectedJob := range expectedJobs { |
| 422 | if opts := expectedJob.Opts; opts != nil { |
| 423 | if schema == "" && opts.Schema != "" || |
| 424 | schema != "" && opts.Schema != "" && schema != opts.Schema { |
| 425 | return nil, fmt.Errorf( |
| 426 | "when setting RequireInsertedOpts.Schema with RequireMany schema should be set only at index 0 or the same schema set for all options; "+ |
| 427 | "expectedJobs[0].Opts.Schema = %q, expectedJobs[%d].Opts.Schema = %q", |
| 428 | schema, i, opts.Schema) |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | // Returned ordered by ID. |
| 434 | jobRows, err := exec.JobGetByKindMany(ctx, &riverdriver.JobGetByKindManyParams{ |
| 435 | Kind: expectedArgsKinds, |
| 436 | Schema: schema, |
| 437 | }) |
| 438 | if err != nil { |
| 439 | return nil, fmt.Errorf("error querying jobs: %w", err) |
| 440 | } |
| 441 | |
| 442 | actualArgsKinds := sliceutil.Map(jobRows, func(j *rivertype.JobRow) string { return j.Kind }) |
| 443 | |
| 444 | if !slices.Equal(expectedArgsKinds, actualArgsKinds) { |
| 445 | failuref(t, "Inserted jobs didn't match expectation; expected: %+v, actual: %+v", |
| 446 | expectedArgsKinds, actualArgsKinds) |
| 447 | return nil, nil |
| 448 | } |
| 449 | |
| 450 | for i, jobRow := range jobRows { |
| 451 | if expectedJobs[i].Opts != nil { |
| 452 | if !compareJobToInsertOpts(t, jobRow, expectedJobs[i].Opts, i, false) { |
| 453 | return nil, nil |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | return jobRows, nil |
| 459 | } |
| 460 | |
| 461 | const rfc3339Micro = "2006-01-02T15:04:05.999999Z07:00" |
nothing calls this directly
no test coverage detected
searching dependent graphs…