Skip to content

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 31, 2024
1 parent ec5222d commit dbd10f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
15 changes: 15 additions & 0 deletions clients/mssql/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ func TestParseValue(t *testing.T) {
assert.Equal(t, "2021-01-01", val.(time.Time).Format(ext.PostgresDateFormat))
}
}
{
// Timestamp NTZ
{
// String
val, err := parseValue("2021-01-04T09:32:00", columns.NewColumn("timestamp_ntz", typing.TimestampNTZ))
assert.NoError(t, err)
assert.Equal(t, time.Date(2021, time.January, 4, 9, 32, 0, 0, time.UTC), val.(time.Time))
}
{
// time.Time
val, err := parseValue(time.Date(2021, time.January, 4, 9, 32, 0, 0, time.UTC), columns.NewColumn("timestamp_ntz", typing.TimestampNTZ))
assert.NoError(t, err)
assert.Equal(t, time.Date(2021, time.January, 4, 9, 32, 0, 0, time.UTC), val.(time.Time))
}
}
{
val, err := parseValue("string value", columns.NewColumn("foo", typing.String))
assert.NoError(t, err)
Expand Down
7 changes: 7 additions & 0 deletions lib/typing/values/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func ToString(colVal any, colKind typing.KindDetails) (string, error) {
}

return _time.Format(ext.PostgresDateFormat), nil
case typing.TimestampNTZ.Kind:
_time, err := ext.ParseTimestampNTZFromInterface(colVal)
if err != nil {
return "", fmt.Errorf("failed to cast colVal as time.Time, colVal: '%v', err: %w", colVal, err)
}

return _time.Format(ext.RFC3339NoTZ), nil
case typing.ETime.Kind:
if err := colKind.EnsureExtendedTimeDetails(); err != nil {
return "", err
Expand Down
15 changes: 15 additions & 0 deletions lib/typing/values/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ func TestToString(t *testing.T) {
assert.Equal(t, "2021-01-01", value)
}
}
{
// Timestamp NTZ
{
// time.Time
value, err := ToString(time.Date(2021, time.January, 1, 17, 33, 4, 150_001_123, time.UTC), typing.TimestampNTZ)
assert.NoError(t, err)
assert.Equal(t, "2021-01-01T17:33:04.150001123", value)
}
{
// String
value, err := ToString("2021-01-01T17:33:04.150001123", typing.TimestampNTZ)
assert.NoError(t, err)
assert.Equal(t, time.Date(2021, time.January, 1, 17, 33, 4, 150_001_123, time.UTC).Format(ext.RFC3339NoTZ), value)
}
}
{
// ETime
{
Expand Down

0 comments on commit dbd10f4

Please sign in to comment.