-
Notifications
You must be signed in to change notification settings - Fork 0
/
timezones_test.go
64 lines (55 loc) · 1.45 KB
/
timezones_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
package timezones
import (
"testing"
)
// TestGetTimeZones ensures that a slice of TimeZone is returned by GetTimeZones
func TestGetTimeZones(t *testing.T) {
timezones := GetTimeZones()
if len(timezones) == 0 {
t.Error("no timezones returned")
}
}
// TestGetTimeZoneByValue ensures that GetTimeZoneByValue finds a correct
// TimeZone by its field Value.
func TestGetTimeZoneByValue(t *testing.T) {
testCases := map[string]string{
"SA Pacific Standard Time": "(UTC-05:00) Bogota, Lima, Quito",
"New Zealand Standard Time": "(UTC+12:00) Auckland, Wellington",
"Tonga Standard Time": "(UTC+13:00) Nuku'alofa",
}
for key, testCase := range testCases {
tz, err := GetTimeZoneByValue(key)
if err != nil {
t.Error(err)
}
if tz.Text != testCase {
t.Errorf("timezone text unexpected, expected \"%v\" but got \"%v\"", testCase, tz.Text)
}
}
}
// TestGetTimeZoneByOffset ensures that TestGetTimeZoneByOffset finds
// all timezones with the same offset as a sample.
func TestGetTimeZoneByOffset(t *testing.T) {
testCases := map[float32]int{
// offset: expected count
-5: 3,
-1: 2,
0: 4,
1: 5,
5: 4,
}
for offset, expectedCount := range testCases {
timeZones, err := GetTimeZoneByOffset(offset)
if err != nil {
t.Error(err)
}
if len(timeZones) != expectedCount {
t.Errorf(
"invalid number of TimeZones returned for offset %v, expected %v but got %v",
offset,
expectedCount,
len(timeZones),
)
}
}
}