-
Notifications
You must be signed in to change notification settings - Fork 124
/
location_test.go
148 lines (143 loc) · 2.9 KB
/
location_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) 2017-2022 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"errors"
"fmt"
"reflect"
"testing"
"time"
)
type tcLocation struct {
ss string
tt string
err error
}
func TestWithOffsetString(t *testing.T) {
testcases := []tcLocation{
{
ss: "+0700",
tt: "+0700",
err: nil,
},
{
ss: "-1200",
tt: "-1200",
err: nil,
},
{
ss: "+0710",
tt: "+0710",
err: nil,
},
{
ss: "1200",
tt: "",
err: &SnowflakeError{
Number: ErrInvalidOffsetStr,
Message: errMsgInvalidOffsetStr,
MessageArgs: []interface{}{"1200"},
},
},
{
ss: "x1200",
tt: "",
err: &SnowflakeError{
Number: ErrInvalidOffsetStr,
Message: errMsgInvalidOffsetStr,
MessageArgs: []interface{}{"x1200"},
},
},
{
ss: "+12001",
tt: "",
err: &SnowflakeError{
Number: ErrInvalidOffsetStr,
Message: errMsgInvalidOffsetStr,
MessageArgs: []interface{}{"+12001"},
},
},
{
ss: "x12001",
tt: "",
err: &SnowflakeError{
Number: ErrInvalidOffsetStr,
Message: errMsgInvalidOffsetStr,
MessageArgs: []interface{}{"x12001"},
},
},
{
ss: "-12CD",
tt: "",
err: errors.New("parse int error"), // can this be more specific?
},
{
ss: "+ABCD",
tt: "",
err: errors.New("parse int error"), // can this be more specific?
},
}
for _, t0 := range testcases {
t.Run(t0.ss, func(t *testing.T) {
loc, err := LocationWithOffsetString(t0.ss)
if t0.err != nil {
if t0.err != err {
driverError1, ok1 := t0.err.(*SnowflakeError)
driverError2, ok2 := err.(*SnowflakeError)
if ok1 && ok2 && driverError1.Number != driverError2.Number {
t.Fatalf("error expected: %v, got: %v", t0.err, err)
}
}
} else {
if err != nil {
t.Fatalf("%v", err)
}
if t0.tt != loc.String() {
t.Fatalf("location string didn't match. expected: %v, got: %v", t0.tt, loc)
}
}
})
}
}
func TestGetCurrentLocation(t *testing.T) {
specificTz := "Pacific/Honolulu"
specificLoc, err := time.LoadLocation(specificTz)
if err != nil {
t.Fatalf("Cannot initialize specific timezone location")
}
incorrectTz := "Not/exists"
testcases := []struct {
params map[string]*string
loc *time.Location
}{
{
params: map[string]*string{},
loc: time.Now().Location(),
},
{
params: map[string]*string{
"timezone": nil,
},
loc: time.Now().Location(),
},
{
params: map[string]*string{
"timezone": &specificTz,
},
loc: specificLoc,
},
{
params: map[string]*string{
"timezone": &incorrectTz,
},
loc: time.Now().Location(),
},
}
for _, tc := range testcases {
t.Run(fmt.Sprintf("%v", tc.loc), func(t *testing.T) {
loc := getCurrentLocation(tc.params)
if !reflect.DeepEqual(*loc, *tc.loc) {
t.Fatalf("location mismatch. expected: %v, got: %v", tc.loc, loc)
}
})
}
}