Skip to content

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Aug 13, 2024
1 parent a39f3cb commit 80a4cdf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clients/mssql/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func parseValue(colVal any, colKind columns.Column) (any, error) {
case *ext.ExtendedTime:
return castedColVal.GetTime(), nil
default:
return nil, fmt.Errorf("expected colVal to be either string or *ext.ExtendedTime, type is: %T", colVal)
return nil, fmt.Errorf("expected colVal to be either string or *ext.ExtendedTime, type is: %T", castedColVal)
}
case typing.String.Kind:
isArray := reflect.ValueOf(colVal).Kind() == reflect.Slice
Expand Down
30 changes: 30 additions & 0 deletions clients/mssql/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package mssql

import (
"testing"
"time"

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

"github.com/artie-labs/transfer/lib/config/constants"

Expand Down Expand Up @@ -93,4 +96,31 @@ func TestParseValue(t *testing.T) {
assert.NoError(t, err)
assert.False(t, val.(bool))
}
{
// Extended time
{
// String
val, err := parseValue("2021-01-01T00:00:00Z", columns.NewColumn("time", typing.ETime))
assert.NoError(t, err)
assert.Equal(t, "2021-01-01T00:00:00Z", val)
}
{
// Extended time object
ts := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)

val, err := parseValue(
ext.NewExtendedTime(ts, ext.DateKindType, ext.ISO8601),
columns.NewColumn("time", typing.ETime),
)
assert.NoError(t, err)
assert.Equal(t, ts, val)
}
{
// Wrong data type
val, err := parseValue(123, columns.NewColumn("time", typing.ETime))
assert.ErrorContains(t, err, "expected colVal to be either string or *ext.ExtendedTime, type is: int")
assert.Nil(t, val)
}

}
}

0 comments on commit 80a4cdf

Please sign in to comment.