-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialization_test.go
61 lines (46 loc) · 1.26 KB
/
serialization_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
49
50
51
52
53
54
55
56
57
58
59
60
61
package yadb
import (
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type TestStruct struct {
ID string `db:"uuid"`
Type int `db:"event_type"`
Date string `db:"event_date"`
DateTime string `db:"event_time"`
EmptyVal string
SkipVal string `db:"-"`
}
func TestSeria(t *testing.T) {
bw, err := NewBatchWriter("events", []string{"uuid", "event_type", "event_time", "event_date"}, 5, time.Second)
assert.NoError(t, err)
errw := bw.InsertMap(map[string]interface{}{
"uuid": "prog_test3",
"event_date": time.Now().Format("2006-01-02"),
"event_time": time.Now().Format("2006-01-02 15:04:05"),
})
assert.Error(t, errw)
str1 := TestStruct{
ID: "prog_test3",
Type: 4,
Date: time.Now().Format("2006-01-02"),
DateTime: time.Now().Format("2006-01-02 15:04:05"),
}
map1 := map[string]interface{}{
"uuid": str1.ID,
"event_type": str1.Type,
"event_date": str1.Date,
"event_time": str1.DateTime,
}
map2 := seria(reflect.ValueOf(&str1))
assert.Equal(t, map1, map2)
map3 := seria(reflect.ValueOf(str1))
assert.Equal(t, map1, map3)
var map0 map[string]interface{}
map4 := seria(reflect.ValueOf(nil))
assert.Equal(t, map0, map4)
errw2 := bw.InsertStruct(&str1)
assert.NoError(t, errw2)
}