Skip to content

Commit

Permalink
Update GetData tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danafallon committed Jul 17, 2024
1 parent 830979f commit fed47e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
16 changes: 11 additions & 5 deletions lib/cdc/mongo/debezium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (m *MongoTestSuite) TestMongoDBEventCustomer() {

assert.Equal(m.T(), nestedData["object"], "foo")
assert.Equal(m.T(), evtData[constants.DeleteColumnMarker], false)
assert.Equal(m.T(), evtData[constants.OnlySetDeleteColumnMarker], false)
assert.Equal(m.T(), evt.GetExecutionTime(),
time.Date(2022, time.November, 18, 6, 35, 21, 0, time.UTC))
assert.Equal(m.T(), "customers", evt.GetTableName())
Expand Down Expand Up @@ -246,8 +247,12 @@ func (m *MongoTestSuite) TestMongoDBEventCustomerBefore_NoData() {
_, isOk := evtData[constants.UpdateColumnMarker]
assert.False(m.T(), isOk)

_, isOk = evtData[constants.DeleteColumnMarker]
deletionFlag, isOk := evtData[constants.DeleteColumnMarker]
assert.True(m.T(), isOk)
assert.True(m.T(), deletionFlag.(bool))
deletionOnlyFlag, isOk := evtData[constants.OnlySetDeleteColumnMarker]
assert.True(m.T(), isOk)
assert.True(m.T(), deletionOnlyFlag.(bool))

assert.Equal(m.T(), evt.GetExecutionTime(), time.Date(2022, time.November, 18, 6, 35, 21, 0, time.UTC))
assert.Equal(m.T(), true, evt.DeletePayload())
Expand Down Expand Up @@ -296,10 +301,11 @@ func (m *MongoTestSuite) TestMongoDBEventCustomerBefore() {
assert.False(m.T(), isOk)

expectedKeyToVal := map[string]any{
"_id": 1003,
constants.DeleteColumnMarker: true,
"first_name": "Robin",
"email": "[email protected]",
"_id": 1003,
constants.DeleteColumnMarker: true,
constants.OnlySetDeleteColumnMarker: true,
"first_name": "Robin",
"email": "[email protected]",
}

for expectedKey, expectedVal := range expectedKeyToVal {
Expand Down
19 changes: 14 additions & 5 deletions lib/cdc/util/relational_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ func TestGetDataTestInsert(t *testing.T) {
deletionFlag, isOk := evtData[constants.DeleteColumnMarker]
assert.True(t, isOk)
assert.False(t, deletionFlag.(bool))
deletionOnlyFlag, isOk := evtData[constants.OnlySetDeleteColumnMarker]
assert.True(t, isOk)
assert.False(t, deletionOnlyFlag.(bool))

_, isOk = evtData[constants.UpdateColumnMarker]
assert.False(t, isOk)

delete(evtData, constants.DeleteColumnMarker)
delete(evtData, constants.OnlySetDeleteColumnMarker)
assert.Equal(t, after, evtData)

evtData, err = schemaEventPayload.GetData(map[string]any{"pk": 1}, &kafkalib.TopicConfig{
Expand All @@ -141,11 +145,12 @@ func TestGetData_TestDelete(t *testing.T) {
}

expectedKeyValues := map[string]any{
"id": int64(1004),
"first_name": "Anne",
"last_name": "Kretchmar",
"email": "[email protected]",
constants.DeleteColumnMarker: true,
"id": int64(1004),
"first_name": "Anne",
"last_name": "Kretchmar",
"email": "[email protected]",
constants.DeleteColumnMarker: true,
constants.OnlySetDeleteColumnMarker: true,
}

kvMap := map[string]any{"pk": 1004}
Expand Down Expand Up @@ -214,11 +219,15 @@ func TestGetDataTestUpdate(t *testing.T) {
deletionFlag, isOk := evtData[constants.DeleteColumnMarker]
assert.True(t, isOk)
assert.False(t, deletionFlag.(bool))
deletionOnlyFlag, isOk := evtData[constants.OnlySetDeleteColumnMarker]
assert.True(t, isOk)
assert.False(t, deletionOnlyFlag.(bool))

_, isOk = evtData[constants.UpdateColumnMarker]
assert.False(t, isOk)

delete(evtData, constants.DeleteColumnMarker)
delete(evtData, constants.OnlySetDeleteColumnMarker)
assert.Equal(t, after, evtData)

evtData, err = schemaEventPayload.GetData(kvMap, &kafkalib.TopicConfig{
Expand Down

0 comments on commit fed47e3

Please sign in to comment.