Skip to content

Commit 4c811d9

Browse files
authored
Merge pull request #153 from xataio/add-integration-tests
Add pg2pg snapshot integration tests
2 parents 651047f + c51f5fa commit 4c811d9

File tree

3 files changed

+160
-127
lines changed

3 files changed

+160
-127
lines changed

pkg/stream/integration/helper_test.go

+38-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ import (
1616
kafkalib "github.com/xataio/pgstream/pkg/kafka"
1717
loglib "github.com/xataio/pgstream/pkg/log"
1818
schemalogpg "github.com/xataio/pgstream/pkg/schemalog/postgres"
19+
pgsnapshotgenerator "github.com/xataio/pgstream/pkg/snapshot/generator/postgres/data"
20+
"github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore"
1921
"github.com/xataio/pgstream/pkg/stream"
2022
"github.com/xataio/pgstream/pkg/tls"
2123
"github.com/xataio/pgstream/pkg/wal"
2224
kafkacheckpoint "github.com/xataio/pgstream/pkg/wal/checkpointer/kafka"
25+
pglistener "github.com/xataio/pgstream/pkg/wal/listener/postgres"
2326
"github.com/xataio/pgstream/pkg/wal/processor/batch"
2427
"github.com/xataio/pgstream/pkg/wal/processor/injector"
2528
kafkaprocessor "github.com/xataio/pgstream/pkg/wal/processor/kafka"
@@ -84,8 +87,17 @@ func runStream(t *testing.T, ctx context.Context, cfg *stream.Config) {
8487
}()
8588
}
8689

90+
func initStream(t *testing.T, ctx context.Context, url string) {
91+
err := stream.Init(ctx, url, "")
92+
require.NoError(t, err)
93+
}
94+
8795
func execQuery(t *testing.T, ctx context.Context, query string) {
88-
conn, err := pglib.NewConn(ctx, pgurl)
96+
execQueryWithURL(t, ctx, pgurl, query)
97+
}
98+
99+
func execQueryWithURL(t *testing.T, ctx context.Context, url, query string) {
100+
conn, err := pglib.NewConn(ctx, url)
89101
require.NoError(t, err)
90102

91103
_, err = conn.Exec(ctx, query)
@@ -108,6 +120,28 @@ func testPostgresListenerCfg() stream.ListenerConfig {
108120
}
109121
}
110122

123+
func testPostgresListenerCfgWithSnapshot(sourceURL, targetURL string, tables []string) stream.ListenerConfig {
124+
return stream.ListenerConfig{
125+
Postgres: &stream.PostgresListenerConfig{
126+
Replication: pgreplication.Config{
127+
PostgresURL: sourceURL,
128+
},
129+
Snapshot: &pglistener.SnapshotConfig{
130+
Generator: pgsnapshotgenerator.Config{
131+
URL: sourceURL,
132+
},
133+
Tables: tables,
134+
Schema: pglistener.SchemaSnapshotConfig{
135+
DumpRestore: &pgdumprestore.Config{
136+
SourcePGURL: sourceURL,
137+
TargetPGURL: targetURL,
138+
},
139+
},
140+
},
141+
},
142+
}
143+
}
144+
111145
func testKafkaListenerCfg() stream.ListenerConfig {
112146
return stream.ListenerConfig{
113147
Kafka: &stream.KafkaListenerConfig{
@@ -164,7 +198,7 @@ func testWebhookProcessorCfg() stream.ProcessorConfig {
164198
}
165199
}
166200

167-
func testPostgresProcessorCfg() stream.ProcessorConfig {
201+
func testPostgresProcessorCfg(sourcePGURL string) stream.ProcessorConfig {
168202
return stream.ProcessorConfig{
169203
Postgres: &stream.PostgresProcessorConfig{
170204
BatchWriter: postgres.Config{
@@ -173,13 +207,13 @@ func testPostgresProcessorCfg() stream.ProcessorConfig {
173207
BatchTimeout: 50 * time.Millisecond,
174208
},
175209
SchemaStore: schemalogpg.Config{
176-
URL: pgurl,
210+
URL: sourcePGURL,
177211
},
178212
},
179213
},
180214
Injector: &injector.Config{
181215
Store: schemalogpg.Config{
182-
URL: pgurl,
216+
URL: sourcePGURL,
183217
},
184218
},
185219
}

0 commit comments

Comments
 (0)