Skip to content

Commit 59a0f5d

Browse files
committed
refactor integration test, add note about delete test
1 parent 4406396 commit 59a0f5d

File tree

1 file changed

+75
-16
lines changed

1 file changed

+75
-16
lines changed

source_integration_test.go

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,68 @@ import (
3838
"github.com/shopspring/decimal"
3939
)
4040

41-
// todo test updates and deletes, for not null and nullable values
42-
func TestSource_ReadN_Snapshot_CDC(t *testing.T) {
41+
type readTestCase struct {
42+
name string
43+
notNullOnly bool
44+
snapshot bool
45+
cdc bool
46+
opDelete bool
47+
}
48+
49+
func TestSource_ReadN(t *testing.T) {
50+
testCases := []readTestCase{
51+
{
52+
name: "snapshot not only only",
53+
notNullOnly: true,
54+
snapshot: true,
55+
},
56+
{
57+
name: "snapshot with nullable values",
58+
notNullOnly: false,
59+
snapshot: true,
60+
},
61+
{
62+
name: "cdc not only only",
63+
notNullOnly: true,
64+
cdc: true,
65+
},
66+
{
67+
name: "cdc with nullable values",
68+
notNullOnly: false,
69+
cdc: true,
70+
},
71+
72+
{
73+
name: "delete cdc data not only only",
74+
notNullOnly: true,
75+
cdc: true,
76+
opDelete: true,
77+
},
78+
{
79+
name: "delete cdc data with nullable values",
80+
notNullOnly: false,
81+
cdc: true,
82+
opDelete: true,
83+
},
84+
}
85+
86+
for _, tc := range testCases {
87+
t.Run(tc.name, func(t *testing.T) {
88+
runReadTest(t, tc)
89+
})
90+
}
91+
}
92+
93+
func runReadTest(t *testing.T, tc readTestCase) {
4394
is := is.New(t)
4495
ctx := test.Context(t)
45-
notNullOnly := false
4696
conn := test.ConnectSimple(ctx, t, test.RepmgrConnString)
4797

4898
tableName := createTableWithManyTypes(ctx, t)
49-
// Write the snapshot data
50-
insertRow(ctx, is, conn, tableName, 1, notNullOnly)
99+
100+
if tc.snapshot {
101+
insertRow(ctx, is, conn, tableName, 1, tc.notNullOnly)
102+
}
51103

52104
slotName := "conduitslot1"
53105
publicationName := "conduitpub1"
@@ -79,20 +131,27 @@ func TestSource_ReadN_Snapshot_CDC(t *testing.T) {
79131
is.NoErr(s.Teardown(ctx))
80132
})
81133

82-
// Read, ack, and assert the snapshot record is OK
83-
rec := readAndAck(ctx, is, s)
84-
assertRecordOK(is, tableName, rec, 1, notNullOnly)
134+
if tc.snapshot {
135+
// Read, ack, and assert the snapshot record is OK
136+
rec := readAndAck(ctx, is, s)
137+
assertRecordOK(is, tableName, rec, 1, tc.notNullOnly)
138+
}
85139

86-
// Write the CDC data
87-
insertRow(ctx, is, conn, tableName, 2, notNullOnly)
140+
if tc.cdc {
141+
insertRow(ctx, is, conn, tableName, 1, tc.notNullOnly)
88142

89-
// Read, ack, and verify the CDC record
90-
rec = readAndAck(ctx, is, s)
91-
assertRecordOK(is, tableName, rec, 2, notNullOnly)
143+
// Read, ack, and verify the CDC record
144+
rec := readAndAck(ctx, is, s)
145+
assertRecordOK(is, tableName, rec, 1, tc.notNullOnly)
146+
}
92147

93-
deleteRow(ctx, is, conn, tableName, 2)
94-
rec = readAndAck(ctx, is, s)
95-
is.Equal(opencdc.OperationDelete, rec.Operation)
148+
if tc.opDelete {
149+
// https://github.com/ConduitIO/conduit-connector-postgres/issues/301
150+
t.Skip("Skipping delete test, see GitHub issue ")
151+
deleteRow(ctx, is, conn, tableName, 1)
152+
rec := readAndAck(ctx, is, s)
153+
is.Equal(opencdc.OperationDelete, rec.Operation)
154+
}
96155
}
97156

98157
func readAndAck(ctx context.Context, is *is.I, s sdk.Source) opencdc.Record {

0 commit comments

Comments
 (0)