Skip to content

Commit

Permalink
Clean up test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jan 23, 2025
1 parent 7e5e494 commit b03cdff
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions models/event/event_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package event
import (
"fmt"
"strconv"
"strings"

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

Expand Down Expand Up @@ -173,21 +174,22 @@ func (e *EventsTestSuite) TestEventSaveOptionalSchema() {
func (e *EventsTestSuite) TestEvent_SaveColumnsNoData() {
var cols columns.Columns
for i := 0; i < 50; i++ {
cols.AddColumn(columns.NewColumn(fmt.Sprint(i), typing.Invalid))
cols.AddColumn(columns.NewColumn(fmt.Sprintf("col_%d", i), typing.Invalid))
}

evt := Event{
Table: "non_existent",
Columns: &cols,
Data: map[string]any{
"1": "123",
"col_1": "123",
constants.DeleteColumnMarker: true,
constants.OnlySetDeleteColumnMarker: true,
},
PrimaryKeyMap: map[string]any{
"1": "123",
"col_1": "123",
},
}

kafkaMsg := kafka.Message{}
_, _, err := evt.Save(e.cfg, e.db, topicConfig, artie.NewMessage(&kafkaMsg, nil, kafkaMsg.Topic))
assert.NoError(e.T(), err)
Expand All @@ -199,19 +201,21 @@ func (e *EventsTestSuite) TestEvent_SaveColumnsNoData() {
continue
}

columnNamePart := strings.Split(col.Name(), "_")[1]

if prevKey == "" {
prevKey = col.Name()
prevKey = columnNamePart
continue
}

currentKeyParsed, err := strconv.Atoi(col.Name())
currentKeyParsed, err := strconv.Atoi(columnNamePart)
assert.NoError(e.T(), err)

prevKeyParsed, err := strconv.Atoi(prevKey)
assert.NoError(e.T(), err)

// Testing ordering.
assert.True(e.T(), currentKeyParsed > prevKeyParsed, fmt.Sprintf("current key: %v, prevKey: %v", currentKeyParsed, prevKeyParsed))
assert.True(e.T(), currentKeyParsed > prevKeyParsed, fmt.Sprintf("current key: %q, prevKey: %q", currentKeyParsed, prevKeyParsed))
}

// Now let's add more keys.
Expand Down

0 comments on commit b03cdff

Please sign in to comment.