forked from mailru/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_converter_test.go
48 lines (42 loc) · 1.43 KB
/
value_converter_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
48
package clickhouse
import (
"database/sql/driver"
"math"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func getUInt64Ptr(v uint64) *uint64 {
return &v
}
func TestConverter(t *testing.T) {
testCases := []struct {
value interface{}
expected driver.Value
msg string
}{
// uint64
{getUInt64Ptr(0), uint64(0), "*uint64(0)"},
{getUInt64Ptr(maxAllowedUInt64), uint64(9223372036854775807), "*uint64(maxAllowedUInt64)"},
{getUInt64Ptr(maxAllowedUInt64 + 1), []byte("9223372036854775808"), "*uint64(maxAllowedUInt64+1)"},
{getUInt64Ptr(maxAllowedUInt64*2 + 1), []byte("18446744073709551615"), "*uint64(maxUInt64)"},
// int64
{int64(0), int64(0), "int64(0)"},
{int64(math.MinInt64), int64(-9223372036854775808), "int64(MinInt64)"},
{int64(math.MaxInt64), int64(9223372036854775807), "int64(MaxInt64)"},
// uint64
{uint64(0), uint64(0), "uint64(0)"},
{uint64(maxAllowedUInt64), uint64(9223372036854775807), "uint64(maxAllowedUInt64)"},
{uint64(maxAllowedUInt64 + 1), []byte("9223372036854775808"), "uint64(maxAllowedUInt64+1)"},
{uint64(maxAllowedUInt64*2 + 1), []byte("18446744073709551615"), "uint64(maxUInt64)"},
}
for _, tc := range testCases {
dv, err := converter{}.ConvertValue(tc.value)
if assert.NoError(t, err) {
// assert.ElementsMatch(t, dv, tc.expected, "failed to convert "+tc.msg)
if !reflect.DeepEqual(tc.expected, dv) {
t.Errorf("failed to convert %s", tc.msg)
}
}
}
}