-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_convert_test.go
More file actions
57 lines (53 loc) · 1.31 KB
/
type_convert_test.go
File metadata and controls
57 lines (53 loc) · 1.31 KB
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
49
50
51
52
53
54
55
56
57
package gibero
import (
"encoding/hex"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestConvert(t *testing.T) {
assert := require.New(t)
var ts int64 = 1689905720186
bt := make([]byte, 12)
fromTimestamps(bt[:], ts)
printFormat("hex :\t [%s] \n", hex.EncodeToString(bt[:]))
assert.Equal(hex.EncodeToString(bt[:]), "787b07150a0f14000b162280", "ts")
bt = make([]byte, 8)
fromDates(bt[:], ts)
printFormat("hex :\t [%s] \n", hex.EncodeToString(bt[:]))
assert.Equal(hex.EncodeToString(bt[:]), "787b071500000000", "date")
}
func TestScan(t *testing.T) {
assert := require.New(t)
{
var scaner scanType = StringScan("test-test")
var v123 string
scaner.scan(&v123)
assert.Equal("test-test", v123)
}
{
var scaner scanType = IntegerScan(1235)
var v123 int32
scaner.scan(&v123)
assert.Equal(int32(1235), v123)
}
{
var scaner scanType = IntegerScan(1235)
var v123 int64
scaner.scan(&v123)
assert.Equal(int64(1235), v123)
}
{
to, _ := time.Parse(time.RFC3339, "2023-01-02T20:18:01+08:00")
expect := to.UnixMilli()
var tmp [12]byte
fromTimestamp(tmp[:], &to)
var scanner scanType = TimestempScan(tmp)
ti := &time.Time{}
scanner.scan(ti)
assert.Equal(expect, ti.UnixMilli(), "date")
var str string
scanner.scan(&str)
assert.Equal("2023-01-02T20:18:01", str, "date")
}
}