forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datatype_test.go
47 lines (43 loc) · 1.24 KB
/
datatype_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2017-2022 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"database/sql/driver"
"fmt"
"testing"
)
type tcDataTypeMode struct {
tp driver.Value
tmode snowflakeType
err error
}
func TestDataTypeMode(t *testing.T) {
var testcases = []tcDataTypeMode{
{tp: DataTypeTimestampLtz, tmode: timestampLtzType, err: nil},
{tp: DataTypeTimestampNtz, tmode: timestampNtzType, err: nil},
{tp: DataTypeTimestampTz, tmode: timestampTzType, err: nil},
{tp: DataTypeDate, tmode: dateType, err: nil},
{tp: DataTypeTime, tmode: timeType, err: nil},
{tp: DataTypeBinary, tmode: binaryType, err: nil},
{tp: DataTypeFixed, tmode: fixedType,
err: fmt.Errorf(errMsgInvalidByteArray, DataTypeFixed)},
{tp: DataTypeReal, tmode: realType,
err: fmt.Errorf(errMsgInvalidByteArray, DataTypeFixed)},
{tp: 123, tmode: nullType,
err: fmt.Errorf(errMsgInvalidByteArray, 123)},
}
for _, ts := range testcases {
tmode, err := dataTypeMode(ts.tp)
if ts.err == nil {
if err != nil {
t.Errorf("failed to get datatype mode: %v", err)
}
if tmode != ts.tmode {
t.Errorf("wrong data type: %v", tmode)
}
} else {
if err == nil {
t.Errorf("should raise an error: %v", ts.err)
}
}
}
}