ccache/item_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2013-10-19 14:36:33 +02:00
package ccache
import (
2014-10-25 02:46:18 +02:00
. "github.com/karlseguin/expect"
"testing"
"time"
2013-10-19 14:36:33 +02:00
)
2014-10-25 02:46:18 +02:00
type ItemTests struct{}
func Test_Item(t *testing.T) {
Expectify(new(ItemTests), t)
}
2014-11-14 01:41:22 +01:00
func (_ *ItemTests) Promotability() {
item := &Item{promotions: 4}
2014-10-25 02:46:18 +02:00
Expect(item.shouldPromote(5)).To.Equal(true)
Expect(item.shouldPromote(5)).To.Equal(false)
2013-10-19 14:36:33 +02:00
}
2014-11-14 01:41:22 +01:00
func (_ *ItemTests) Expired() {
now := time.Now().Unix()
item1 := &Item{expires: now + 1}
item2 := &Item{expires: now - 1}
Expect(item1.Expired()).To.Equal(false)
Expect(item2.Expired()).To.Equal(true)
}
2014-11-14 01:41:22 +01:00
func (_ *ItemTests) TTL() {
now := time.Now().Unix()
item1 := &Item{expires: now + 10}
item2 := &Item{expires: now - 10}
Expect(item1.TTL()).To.Equal(time.Second * 10)
Expect(item2.TTL()).To.Equal(time.Second * -10)
}
2014-11-14 01:41:22 +01:00
func (_ *ItemTests) Expires() {
now := time.Now().Unix()
2014-10-27 02:27:26 +01:00
item := &Item{expires: now + 10}
Expect(item.Expires().Unix()).To.Equal(now + 10)
}
2014-11-14 01:41:22 +01:00
func (_ *ItemTests) Extend() {
2014-10-27 02:27:26 +01:00
item := &Item{expires: time.Now().Unix() + 10}
item.Extend(time.Minute * 2)
Expect(item.Expires().Unix()).To.Equal(time.Now().Unix() + 120)
}