@@ -28,7 +28,6 @@ import (
2828 "github.com/google/go-cmp/cmp"
2929 "github.com/google/go-cmp/cmp/cmpopts"
3030 "github.com/jackc/pglogrepl"
31- "github.com/jackc/pgx/v5/pgconn"
3231 "github.com/jackc/pgx/v5/pgxpool"
3332 "github.com/matryer/is"
3433)
@@ -40,12 +39,10 @@ func TestCDCIterator_New(t *testing.T) {
4039 tests := []struct {
4140 name string
4241 setup func (t * testing.T ) CDCConfig
43- pgconf * pgconn.Config
4442 wantErr error
4543 }{
4644 {
47- name : "publication already exists" ,
48- pgconf : & pool .Config ().ConnConfig .Config ,
45+ name : "publication already exists" ,
4946 setup : func (t * testing.T ) CDCConfig {
5047 is := is .New (t )
5148 table := test .SetupTestTable (ctx , t , pool )
@@ -66,21 +63,7 @@ func TestCDCIterator_New(t *testing.T) {
6663 },
6764 },
6865 {
69- name : "fails to connect" ,
70- pgconf : func () * pgconn.Config {
71- c := pool .Config ().ConnConfig .Config
72- c .Port = 31337
73-
74- return & c
75- }(),
76- setup : func (* testing.T ) CDCConfig {
77- return CDCConfig {}
78- },
79- wantErr : errors .New ("could not establish replication connection" ),
80- },
81- {
82- name : "fails to create publication" ,
83- pgconf : & pool .Config ().ConnConfig .Config ,
66+ name : "fails to create publication" ,
8467 setup : func (* testing.T ) CDCConfig {
8568 return CDCConfig {
8669 PublicationName : "foobar" ,
@@ -89,8 +72,7 @@ func TestCDCIterator_New(t *testing.T) {
8972 wantErr : errors .New ("requires at least one table" ),
9073 },
9174 {
92- name : "fails to create subscription" ,
93- pgconf : & pool .Config ().ConnConfig .Config ,
75+ name : "fails to create subscription" ,
9476 setup : func (t * testing.T ) CDCConfig {
9577 is := is .New (t )
9678 table := test .SetupTestTable (ctx , t , pool )
@@ -118,7 +100,7 @@ func TestCDCIterator_New(t *testing.T) {
118100
119101 config := tt .setup (t )
120102
121- _ , err := NewCDCIterator (ctx , tt . pgconf , config )
103+ i , err := NewCDCIterator (ctx , pool , config )
122104 if tt .wantErr != nil {
123105 if match := strings .Contains (err .Error (), tt .wantErr .Error ()); ! match {
124106 t .Logf ("%s != %s" , err .Error (), tt .wantErr .Error ())
@@ -127,6 +109,9 @@ func TestCDCIterator_New(t *testing.T) {
127109 } else {
128110 is .NoErr (err )
129111 }
112+ if i != nil {
113+ is .NoErr (i .Teardown (ctx ))
114+ }
130115 })
131116 }
132117}
@@ -276,8 +261,6 @@ func TestCDCIterator_Next_Fail(t *testing.T) {
276261}
277262
278263func TestCDCIterator_EnsureLSN (t * testing.T ) {
279- // t.Skip()
280-
281264 ctx := context .Background ()
282265 is := is .New (t )
283266
@@ -370,13 +353,6 @@ func TestCDCIterator_Ack(t *testing.T) {
370353 }
371354}
372355
373- func Test_withReplication (t * testing.T ) {
374- is := is .New (t )
375-
376- c := withReplication (& pgconn.Config {})
377- is .Equal (c .RuntimeParams ["replication" ], "database" )
378- }
379-
380356func testCDCIterator (ctx context.Context , t * testing.T , pool * pgxpool.Pool , table string , start bool ) * CDCIterator {
381357 is := is .New (t )
382358 config := CDCConfig {
@@ -386,7 +362,7 @@ func testCDCIterator(ctx context.Context, t *testing.T, pool *pgxpool.Pool, tabl
386362 SlotName : table , // table is random, reuse for slot name
387363 }
388364
389- i , err := NewCDCIterator (ctx , & pool . Config (). ConnConfig . Config , config )
365+ i , err := NewCDCIterator (ctx , pool , config )
390366 is .NoErr (err )
391367
392368 i .sub .StatusTimeout = 1 * time .Second
0 commit comments