-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.go
86 lines (82 loc) · 2.4 KB
/
utils_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
package golongpoll
import (
"testing"
"time"
)
func Test_millisecondStringToTime(t *testing.T) {
inputs := []string{
"0",
"1429972200000",
"1446508745000",
}
type tePair struct {
Time time.Time
Error error
}
expected_outputs := []tePair{
{time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC), nil},
{time.Date(2015, time.April, 25, 14, 30, 0, 0, time.UTC), nil},
{time.Date(2015, time.November, 2, 23, 59, 5, 0, time.UTC), nil},
}
for index, input := range inputs {
actualTime, actualError := millisecondStringToTime(input)
if actualTime != expected_outputs[index].Time ||
actualError != expected_outputs[index].Error {
t.Errorf("Expected (%q, %q), got (%q, %q).",
expected_outputs[index].Time, expected_outputs[index].Error,
actualTime, actualError)
}
}
}
func Test_millisecondStringToTime_InvalidInput(t *testing.T) {
inputs := []string{
"",
"0a",
"a0",
"-adsfjkl",
" ",
"\t\b",
}
type tsPair struct {
Time time.Time
ErrorString string
}
expected_outputs := []tsPair{
{time.Time{}, "strconv.ParseInt: parsing \"\": invalid syntax"},
{time.Time{}, "strconv.ParseInt: parsing \"0a\": invalid syntax"},
{time.Time{}, "strconv.ParseInt: parsing \"a0\": invalid syntax"},
{time.Time{}, "strconv.ParseInt: parsing \"-adsfjkl\": invalid syntax"},
{time.Time{}, "strconv.ParseInt: parsing \" \": invalid syntax"},
{time.Time{}, "strconv.ParseInt: parsing \"\\t\\b\": invalid syntax"},
}
for index, input := range inputs {
actualTime, actualError := millisecondStringToTime(input)
if actualTime != expected_outputs[index].Time || actualError.Error() !=
expected_outputs[index].ErrorString {
t.Errorf("Expected (%q, %q), got (%q, %q).",
expected_outputs[index].Time,
expected_outputs[index].ErrorString,
actualTime, actualError.Error())
}
}
}
func Test_timeToEpochMilliseconds(t *testing.T) {
inputs := []time.Time{
time.Date(1969, time.December, 31, 23, 59, 59, 0, time.UTC),
time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC),
time.Date(2015, time.April, 25, 14, 30, 0, 0, time.UTC),
time.Date(2015, time.November, 2, 23, 59, 5, 0, time.UTC),
}
expected_outputs := []int64{
-1000,
0,
1429972200000,
1446508745000,
}
for index, input := range inputs {
actual := timeToEpochMilliseconds(input)
if actual != expected_outputs[index] {
t.Errorf("Expected %d, got %d.", expected_outputs[index], actual)
}
}
}