-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sql] Add tests for
Dialect.KindForDataType
- Loading branch information
1 parent
9ed0c94
commit 6f229f3
Showing
4 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/artie-labs/transfer/lib/typing" | ||
"github.com/artie-labs/transfer/lib/typing/ext" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMSSQLDialect_KindForDataType(t *testing.T) { | ||
dialect := MSSQLDialect{} | ||
|
||
colToExpectedKind := map[string]typing.KindDetails{ | ||
"char": typing.String, | ||
"varchar": typing.String, | ||
"nchar": typing.String, | ||
"nvarchar": typing.String, | ||
"ntext": typing.String, | ||
"text": typing.String, | ||
"smallint": typing.Integer, | ||
"tinyint": typing.Integer, | ||
"int": typing.Integer, | ||
"float": typing.Float, | ||
"real": typing.Float, | ||
"bit": typing.Boolean, | ||
"date": typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateKindType), | ||
"time": typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimeKindType), | ||
"datetime": typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateTimeKindType), | ||
"datetime2": typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateTimeKindType), | ||
} | ||
|
||
for col, expectedKind := range colToExpectedKind { | ||
kd, err := dialect.KindForDataType(col, "") | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedKind.Kind, kd.Kind, col) | ||
} | ||
|
||
{ | ||
_, err := dialect.KindForDataType("numeric(5", "") | ||
assert.ErrorContains(t, err, "missing closing parenthesis") | ||
} | ||
{ | ||
kd, err := dialect.KindForDataType("numeric(5, 2)", "") | ||
assert.NoError(t, err) | ||
assert.Equal(t, typing.EDecimal.Kind, kd.Kind) | ||
assert.Equal(t, 5, *kd.ExtendedDecimalDetails.Precision()) | ||
assert.Equal(t, 2, kd.ExtendedDecimalDetails.Scale()) | ||
} | ||
{ | ||
kd, err := dialect.KindForDataType("char", "5") | ||
assert.NoError(t, err) | ||
assert.Equal(t, typing.String.Kind, kd.Kind) | ||
assert.Equal(t, 5, *kd.OptionalStringPrecision) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters