forked from NuVotifier/go-votifier
-
Notifications
You must be signed in to change notification settings - Fork 2
/
util_test.go
45 lines (37 loc) · 1.08 KB
/
util_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
package votifier
import (
"strconv"
"testing"
"time"
)
func TestParseTime(t *testing.T) {
now := time.Now()
t.Run("Valid Unix Millis", func(t *testing.T) {
unixMillis := strconv.FormatInt(now.UnixMilli(), 10)
parsedTime := parseTime(unixMillis)
expectedTime := now.UnixMilli()
actualTime := parsedTime.UnixMilli()
if expectedTime != actualTime {
t.Errorf("Expected %v, but got %v", expectedTime, actualTime)
}
})
t.Run("Invalid Unix Millis", func(t *testing.T) {
unixMillis := "invalid"
parsedTime := parseTime(unixMillis)
expectedTime := now.UnixMilli()
actualTime := parsedTime.UnixMilli()
if expectedTime != actualTime {
t.Errorf("Expected %v, but got %v", expectedTime, actualTime)
}
})
t.Run("Older than 1 hour", func(t *testing.T) {
oneHourAgo := now.Add(-2 * time.Hour)
unixMillis := strconv.FormatInt(oneHourAgo.UnixMilli(), 10)
parsedTime := parseTime(unixMillis)
expectedTime := now.UnixMilli()
actualTime := parsedTime.UnixMilli()
if expectedTime != actualTime {
t.Errorf("Expected %v, but got %v", expectedTime, actualTime)
}
})
}