11package ccache
22
33import (
4- . "github.com/karlseguin/expect "
4+ "math "
55 "testing"
66 "time"
7+
8+ . "github.com/karlseguin/expect"
79)
810
911type ItemTests struct {}
@@ -19,29 +21,29 @@ func (_ *ItemTests) Promotability() {
1921}
2022
2123func (_ * ItemTests ) Expired () {
22- now := time .Now ().Unix ()
23- item1 := & Item {expires : now + 1 }
24- item2 := & Item {expires : now - 1 }
24+ now := time .Now ().UnixNano ()
25+ item1 := & Item {expires : now + ( 10 * int64 ( time . Millisecond )) }
26+ item2 := & Item {expires : now - ( 10 * int64 ( time . Millisecond )) }
2527 Expect (item1 .Expired ()).To .Equal (false )
2628 Expect (item2 .Expired ()).To .Equal (true )
2729}
2830
2931func (_ * ItemTests ) TTL () {
30- now := time .Now ().Unix ()
31- item1 := & Item {expires : now + 10 }
32- item2 := & Item {expires : now - 10 }
33- Expect (item1 .TTL ()) .To .Equal (time . Second * 10 )
34- Expect (item2 .TTL ()) .To .Equal (time . Second * - 10 )
32+ now := time .Now ().UnixNano ()
33+ item1 := & Item {expires : now + int64 ( time . Second ) }
34+ item2 := & Item {expires : now - int64 ( time . Second ) }
35+ Expect (int ( math . Ceil ( item1 .TTL (). Seconds ()))) .To .Equal (1 )
36+ Expect (int ( math . Ceil ( item2 .TTL (). Seconds ()))) .To .Equal (- 1 )
3537}
3638
3739func (_ * ItemTests ) Expires () {
38- now := time .Now ().Unix ()
39- item := & Item {expires : now + 10 }
40- Expect (item .Expires ().Unix ()).To .Equal (now + 10 )
40+ now := time .Now ().UnixNano ()
41+ item := & Item {expires : now + ( 10 ) }
42+ Expect (item .Expires ().UnixNano ()).To .Equal (now + 10 )
4143}
4244
4345func (_ * ItemTests ) Extend () {
44- item := & Item {expires : time .Now ().Unix () + 10 }
46+ item := & Item {expires : time .Now ().UnixNano () + 10 }
4547 item .Extend (time .Minute * 2 )
4648 Expect (item .Expires ().Unix ()).To .Equal (time .Now ().Unix () + 120 )
4749}
0 commit comments