RunReplicationScript runs the given ReplicationTest.
(t *testing.T, dsn string, script ReplicationTest)
| 695 | |
| 696 | // RunReplicationScript runs the given ReplicationTest. |
| 697 | func RunReplicationScript(t *testing.T, dsn string, script ReplicationTest) { |
| 698 | scriptDatabase := script.Database |
| 699 | if len(scriptDatabase) == 0 { |
| 700 | scriptDatabase = "postgres" |
| 701 | } |
| 702 | |
| 703 | // primaryDns is the connection to the actual postgres database. |
| 704 | // If you have postgres running on a different port, you'll need to change this. |
| 705 | primaryDns := dsn + "?sslmode=disable" |
| 706 | |
| 707 | ctx, pgServer, replicaConn, close, err := pgtest.CreateTestServer(t, findFreePort()) |
| 708 | require.NoError(t, err) |
| 709 | defer func() { |
| 710 | replicaConn.Close(ctx) |
| 711 | err := close() |
| 712 | require.NoError(t, err) |
| 713 | }() |
| 714 | |
| 715 | ctx = context.Background() |
| 716 | t.Run(script.Name, func(t *testing.T) { |
| 717 | runReplicationScript(ctx, t, script, pgServer, replicaConn, primaryDns) |
| 718 | }) |
| 719 | } |
| 720 | |
| 721 | func newReplicator(sqlCtx *sql.Context, t *testing.T, primaryDns string) *logrepl.LogicalReplicator { |
| 722 | err := logrepl.CreateSubscription(sqlCtx, subscriptionName, primaryDns, slotName, pglogrepl.LSN(0).String(), true) |
no test coverage detected