RunScripts runs the given collection of scripts.
(t *testing.T, scripts []ReplicationTest)
| 646 | |
| 647 | // RunScripts runs the given collection of scripts. |
| 648 | func RunReplicationScripts(t *testing.T, scripts []ReplicationTest) { |
| 649 | // First, we'll run through the scripts to check for the Focus variable. If it's true, then append it to the new slice. |
| 650 | focusScripts := make([]ReplicationTest, 0, len(scripts)) |
| 651 | for _, script := range scripts { |
| 652 | if script.Focus { |
| 653 | // If this is running in GitHub Actions, then we'll panic, because someone forgot to disable it before committing |
| 654 | if _, ok := os.LookupEnv("GITHUB_ACTION"); ok { |
| 655 | panic(fmt.Sprintf("The script `%s` has Focus set to `true`. GitHub Actions requires that "+ |
| 656 | "all tests are run, which Focus circumvents, leading to this error. Please disable Focus on "+ |
| 657 | "all tests.", script.Name)) |
| 658 | } |
| 659 | focusScripts = append(focusScripts, script) |
| 660 | } |
| 661 | } |
| 662 | // If we have scripts with Focus set, then we replace the normal script slice with the new slice. |
| 663 | if len(focusScripts) > 0 { |
| 664 | scripts = focusScripts |
| 665 | } |
| 666 | |
| 667 | // start the docker container |
| 668 | containerName, dsn, _, err := StartPostgresServer() |
| 669 | require.NoError(t, err) |
| 670 | defer func() { |
| 671 | err := exec.Command("docker", "kill", containerName).Run() |
| 672 | require.NoError(t, err) |
| 673 | }() |
| 674 | |
| 675 | primaryDns := dsn + "?sslmode=disable" |
| 676 | |
| 677 | // We drop and recreate the replication slot once at the beginning of the test suite. Postgres seems to do a little |
| 678 | // work in the background with a publication, so we need to wait a little bit before running any test scripts. |
| 679 | require.NoError(t, logrepl.DropPublication(primaryDns, slotName)) |
| 680 | require.NoError(t, logrepl.CreatePublicationIfNotExists(primaryDns, slotName)) |
| 681 | time.Sleep(500 * time.Millisecond) |
| 682 | |
| 683 | // for i, script := range scripts { |
| 684 | // if i == 10 { |
| 685 | // RunReplicationScript(t, dsn, script) |
| 686 | // } |
| 687 | // } |
| 688 | for _, script := range scripts { |
| 689 | RunReplicationScript(t, dsn, script) |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | const slotName = "myduck_slot" |
| 694 | const subscriptionName = "my_sub_test" |
no test coverage detected