Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 19, 2024
1 parent 493034d commit 1231da6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/debezium/converters/time_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package converters

import (
"github.com/artie-labs/transfer/lib/debezium/converters"
"math"
"testing"
"time"
Expand Down Expand Up @@ -291,21 +292,40 @@ func TestZonedTimestampConverter_Convert(t *testing.T) {
}
{
// time.Time (ms)
value, err := converter.Convert(time.Date(2001, 2, 3, 4, 5, 1, 900000, time.UTC))
_ts := time.Date(2001, 2, 3, 4, 5, 1, 900000, time.UTC)
value, err := converter.Convert(_ts)
assert.NoError(t, err)
assert.Equal(t, "2001-02-03T04:05:01.0009Z", value)

// Check Transfer to ensure no precision loss
ts, err := converters.DateTimeWithTimezone{}.Convert(value)
assert.NoError(t, err)
assert.Equal(t, _ts, ts.(*ext.ExtendedTime).GetTime())
}
{
// time.Time (microseconds)
value, err := converter.Convert(time.Date(2001, 2, 3, 4, 5, 1, 909000, time.UTC))
_ts := time.Date(2001, 2, 3, 4, 5, 1, 909000, time.UTC)
value, err := converter.Convert(_ts)
assert.NoError(t, err)
assert.Equal(t, "2001-02-03T04:05:01.000909Z", value)

// Check Transfer to ensure no precision loss
ts, err := converters.DateTimeWithTimezone{}.Convert(value)
assert.NoError(t, err)
assert.Equal(t, _ts, ts.(*ext.ExtendedTime).GetTime())
}
{
// time.Time (nanoseconds)
value, err := converter.Convert(time.Date(2001, 2, 3, 4, 5, 1, 9099999, time.UTC))
_ts := time.Date(2001, 2, 3, 4, 5, 1, 9099999, time.UTC)

value, err := converter.Convert(_ts)
assert.NoError(t, err)
assert.Equal(t, "2001-02-03T04:05:01.0090999Z", value)

// Check Transfer to ensure no precision loss
ts, err := converters.DateTimeWithTimezone{}.Convert(value)
assert.NoError(t, err)
assert.Equal(t, _ts, ts.(*ext.ExtendedTime).GetTime())
}
{
// Different timezone
Expand Down

0 comments on commit 1231da6

Please sign in to comment.