Skip to content

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Apr 11, 2024
1 parent ccefd70 commit 5e7b475
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions lib/cdc/util/relational_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package util

import (
"encoding/json"
"fmt"
"testing"
"time"

"github.com/artie-labs/transfer/lib/typing/ext"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/kafkalib"
"github.com/artie-labs/transfer/lib/typing"
Expand Down Expand Up @@ -130,37 +129,31 @@ func TestGetDataTestInsert(t *testing.T) {
assert.True(t, isOk)
}

func TestGetDataTestDelete(t *testing.T) {
func TestGetData_TestDelete(t *testing.T) {
tc := &kafkalib.TopicConfig{
IdempotentKey: "updated_at",
}

now := time.Now().UTC()
schemaEventPayload := SchemaEventPayload{
Payload: Payload{
Before: nil,
After: nil,
Operation: "c",
Source: Source{TsMs: now.UnixMilli()},
},
}

assert.False(t, schemaEventPayload.DeletePayload())
kvMap := map[string]any{"pk": 1004}
var schemaEventPayload SchemaEventPayload
assert.NoError(t, json.Unmarshal([]byte(PostgresDelete), &schemaEventPayload))

kvMap := map[string]any{"pk": 1}
evtData := schemaEventPayload.GetData(kvMap, tc)
shouldDelete, isOk := evtData[constants.DeleteColumnMarker]
assert.True(t, isOk)
assert.True(t, shouldDelete.(bool))
assert.True(t, schemaEventPayload.DeletePayload())
data := schemaEventPayload.GetData(kvMap, tc)
fmt.Println("data", data)

assert.Equal(t, 3, len(evtData), evtData)
assert.Equal(t, evtData["pk"], 1)
assert.Equal(t, evtData[tc.IdempotentKey], now.Format(ext.ISO8601))
expectedKeyValues := map[string]any{
"id": 1004,
"first_name": "Anne",
"last_name": "Kretchmar",
"email": "annek@noanswer.org",
}

tc.IdempotentKey = ""
evtData = schemaEventPayload.GetData(kvMap, tc)
_, isOk = evtData[tc.IdempotentKey]
assert.False(t, isOk, evtData)
for expectedKey, expectedValue := range expectedKeyValues {
value, isOk := data[expectedKey]
assert.True(t, isOk)
assert.Equal(t, expectedValue, value)
}
}

func TestGetDataTestUpdate(t *testing.T) {
Expand Down

0 comments on commit 5e7b475

Please sign in to comment.