forked from YoungPioneers/blog4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeCache_test.go
39 lines (31 loc) · 958 Bytes
/
timeCache_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
// Copyright (c) 2015, huangjunwei <huangjunwei@youmi.net>. All rights reserved.
package blog4go
import (
"testing"
"time"
)
func TestTimeCacheUpdate(t *testing.T) {
// first time
// time
if (time.Time{}) == timeCache.Now() {
t.Error("time cache not correct when init, time wrong")
}
// date
if timeCache.Date() != time.Now().Format(DateFormat) {
t.Error("time cache not correct when init, date wrong")
}
// dateYesterday
if timeCache.DateYesterday() != time.Now().Add(-24*time.Hour).Format(DateFormat) {
t.Error("time cache not correct when init, dateYesterday wrong")
}
time.Sleep(1500 * time.Millisecond)
// when updated
// date
if timeCache.Date() != time.Now().Format(DateFormat) {
t.Error("time cache not correct when updated, date wrong")
}
// dateYesterday
if timeCache.DateYesterday() != time.Now().Add(-24*time.Hour).Format(DateFormat) {
t.Error("time cache not correct when updated, dateYesterday wrong")
}
}