-
Notifications
You must be signed in to change notification settings - Fork 36
/
select_builder_test.go
74 lines (64 loc) · 2.05 KB
/
select_builder_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
62
63
64
65
66
67
68
69
70
71
72
73
74
package dbr
import (
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type innerTestStruct struct {
InnerTime time.Time
InnerNonTime int64
}
type testStruct struct {
innerTestStruct
Time time.Time
Inner innerTestStruct
InnerPtr *innerTestStruct
InnerSlice []innerTestStruct
InnerSlicePtr []*innerTestStruct
InnerMap map[int]*innerTestStruct
}
func TestChangeTimezone(t *testing.T) {
location := "America/New_York"
v := testStruct{
innerTestStruct: innerTestStruct{
InnerTime: time.Date(2020, 1, 20, 8, 0, 0, 0, time.UTC),
},
Time: time.Date(2020, 1, 21, 9, 0, 0, 0, time.UTC),
Inner: innerTestStruct{
InnerTime: time.Date(2020, 1, 22, 10, 0, 0, 0, time.UTC),
},
InnerPtr: &innerTestStruct{
InnerTime: time.Date(2020, 1, 23, 11, 0, 0, 0, time.UTC),
},
InnerSlice: []innerTestStruct{
{InnerTime: time.Date(2020, 1, 24, 12, 0, 0, 0, time.UTC)},
{InnerTime: time.Date(2020, 1, 25, 13, 0, 0, 0, time.UTC)},
},
InnerSlicePtr: []*innerTestStruct{
{InnerTime: time.Date(2020, 1, 26, 14, 0, 0, 0, time.UTC)},
{InnerTime: time.Date(2020, 1, 27, 15, 0, 0, 0, time.UTC)},
},
InnerMap: map[int]*innerTestStruct{
1: {InnerTime: time.Date(2020, 1, 28, 16, 0, 0, 0, time.UTC)},
2: {InnerTime: time.Date(2020, 1, 28, 16, 0, 0, 0, time.UTC)},
},
}
b := &selectBuilder{}
l, _ := time.LoadLocation(location)
b.InTimezone(l)
b.changeTimezone(reflect.ValueOf(&v))
assert.Equal(t, "America/New_York", v.InnerTime.Location().String())
assert.Equal(t, "America/New_York", v.Time.Location().String())
assert.Equal(t, "America/New_York", v.Inner.InnerTime.Location().String())
assert.Equal(t, "America/New_York", v.InnerPtr.InnerTime.Location().String())
for _, tt := range v.InnerSlice {
assert.Equal(t, "America/New_York", tt.InnerTime.Location().String())
}
for _, tt := range v.InnerSlicePtr {
assert.Equal(t, "America/New_York", tt.InnerTime.Location().String())
}
for _, tt := range v.InnerMap {
assert.Equal(t, "America/New_York", tt.InnerTime.Location().String())
}
}