Skip to content

Commit

Permalink
Adding more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 22, 2024
1 parent ee4d09e commit d982d8e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/debezium/converters/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,31 @@ func TestConvertTimeWithTimezone(t *testing.T) {
assert.ErrorContains(t, err, `failed to parse "23:02": parsing time`)
}
{
// What Debezium + Reader would produce
// What Debezium + Reader would produce (microsecond precision)
val, err := TimeWithTimezone{}.Convert("23:02:06.745116Z")
ts, isOk := val.(*ext.ExtendedTime)
assert.True(t, isOk)
assert.NoError(t, err)

expectedTs := ext.NewExtendedTime(time.Date(0, 1, 1, 23, 2, 6, 745116000, time.UTC), ext.TimeKindType, "15:04:05.999999Z")
assert.Equal(t, expectedTs, ts)
assert.Equal(t, expectedTs, val.(*ext.ExtendedTime))
assert.Equal(t, "23:02:06.745116Z", val.(*ext.ExtendedTime).String(""))
}
{
// ms precision
val, err := TimeWithTimezone{}.Convert("23:02:06.745Z")
assert.NoError(t, err)

expectedTs := ext.NewExtendedTime(time.Date(0, 1, 1, 23, 2, 6, 745000000, time.UTC), ext.TimeKindType, "15:04:05.999999Z")
assert.Equal(t, expectedTs, val.(*ext.ExtendedTime))
assert.Equal(t, "23:02:06.745Z", val.(*ext.ExtendedTime).String(""))
}
{
// no fractional seconds
val, err := TimeWithTimezone{}.Convert("23:02:06Z")
assert.NoError(t, err)

expectedTs := ext.NewExtendedTime(time.Date(0, 1, 1, 23, 2, 6, 0, time.UTC), ext.TimeKindType, "15:04:05.999999Z")
assert.Equal(t, expectedTs, val.(*ext.ExtendedTime))
assert.Equal(t, "23:02:06Z", val.(*ext.ExtendedTime).String(""))
}
{
// Non UTC
Expand Down

0 comments on commit d982d8e

Please sign in to comment.