2013-10-19 14:36:33 +02:00
|
|
|
package ccache
|
|
|
|
|
|
|
|
import (
|
2014-10-25 02:46:18 +02:00
|
|
|
. "github.com/karlseguin/expect"
|
2014-02-28 13:10:42 +01:00
|
|
|
"testing"
|
2014-10-25 12:15:47 +02:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *ItemTests) Promotability() {
|
2014-02-28 13:10:42 +01:00
|
|
|
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-10-25 12:15:47 +02:00
|
|
|
|
|
|
|
func (i *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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *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)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (i *ItemTests) Expires() {
|
|
|
|
now := time.Now().Unix()
|
|
|
|
item1 := &Item{expires: now + 10}
|
|
|
|
Expect(item1.Expires().Unix()).To.Equal(now + 10)
|
|
|
|
}
|