The last boolean indicates whether the function's being invoked for RequireInserted versus RequireNotInserted. Each need to perform similar equality checks (thereby using a single helper), but their semantics for succeeds versus failure are orthogonal. RequireInserted only succeeds if every propert
(t testingT, jobRow *rivertype.JobRow, expectedOpts *RequireInsertedOpts, index int, requireNotInserted bool)
| 474 | // equality, a set of failures is built up, and a final failure message of them |
| 475 | // all combined emitted at the end. |
| 476 | func compareJobToInsertOpts(t testingT, jobRow *rivertype.JobRow, expectedOpts *RequireInsertedOpts, index int, requireNotInserted bool) bool { |
| 477 | t.Helper() |
| 478 | |
| 479 | // Adds an index position for the case of multiple expected jobs. Wrapped in |
| 480 | // a function so that the string is only marshaled if needed. |
| 481 | positionStr := func() string { |
| 482 | if index == -1 { |
| 483 | return "" |
| 484 | } |
| 485 | return fmt.Sprintf(" (expected job slice index %d)", index) |
| 486 | } |
| 487 | |
| 488 | var failures []string |
| 489 | |
| 490 | if expectedOpts.MaxAttempts != 0 { |
| 491 | if jobRow.MaxAttempts == expectedOpts.MaxAttempts { |
| 492 | if requireNotInserted { |
| 493 | failures = append(failures, fmt.Sprintf("max attempts equal to excluded %d", expectedOpts.MaxAttempts)) |
| 494 | } |
| 495 | } else { |
| 496 | if requireNotInserted { |
| 497 | return true // any one property doesn't match; assertion passes |
| 498 | } else { |
| 499 | failures = append(failures, fmt.Sprintf("max attempts %d not equal to expected %d", jobRow.MaxAttempts, expectedOpts.MaxAttempts)) |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | if expectedOpts.Priority != 0 { |
| 505 | if jobRow.Priority == expectedOpts.Priority { |
| 506 | if requireNotInserted { |
| 507 | failures = append(failures, fmt.Sprintf("priority equal to excluded %d", expectedOpts.Priority)) |
| 508 | } |
| 509 | } else { |
| 510 | if requireNotInserted { |
| 511 | return true // any one property doesn't match; assertion passes |
| 512 | } else { |
| 513 | failures = append(failures, fmt.Sprintf("priority %d not equal to expected %d", jobRow.Priority, expectedOpts.Priority)) |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | if expectedOpts.Queue != "" { |
| 519 | if jobRow.Queue == expectedOpts.Queue { |
| 520 | if requireNotInserted { |
| 521 | failures = append(failures, fmt.Sprintf("queue equal to excluded '%s'", expectedOpts.Queue)) |
| 522 | } |
| 523 | } else { |
| 524 | if requireNotInserted { |
| 525 | return true // any one property doesn't match; assertion passes |
| 526 | } else { |
| 527 | failures = append(failures, fmt.Sprintf("queue '%s' not equal to expected '%s'", jobRow.Queue, expectedOpts.Queue)) |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | // We have to be more careful when comparing times because Postgres only |
| 533 | // stores them to microsecond-level precision and the given time is likely |
no test coverage detected
searching dependent graphs…