...

Source file src/github.com/launchdarkly/ccache/item_test.go

Documentation: github.com/launchdarkly/ccache

     1  package ccache
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  	"time"
     7  
     8  	. "github.com/karlseguin/expect"
     9  )
    10  
    11  type ItemTests struct{}
    12  
    13  func Test_Item(t *testing.T) {
    14  	Expectify(new(ItemTests), t)
    15  }
    16  
    17  func (_ *ItemTests) Promotability() {
    18  	item := &Item{promotions: 4}
    19  	Expect(item.shouldPromote(5)).To.Equal(true)
    20  	Expect(item.shouldPromote(5)).To.Equal(false)
    21  }
    22  
    23  func (_ *ItemTests) Expired() {
    24  	now := time.Now().UnixNano()
    25  	item1 := &Item{expires: now + (10 * int64(time.Millisecond))}
    26  	item2 := &Item{expires: now - (10 * int64(time.Millisecond))}
    27  	Expect(item1.Expired()).To.Equal(false)
    28  	Expect(item2.Expired()).To.Equal(true)
    29  }
    30  
    31  func (_ *ItemTests) TTL() {
    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)
    37  }
    38  
    39  func (_ *ItemTests) Expires() {
    40  	now := time.Now().UnixNano()
    41  	item := &Item{expires: now + (10)}
    42  	Expect(item.Expires().UnixNano()).To.Equal(now + 10)
    43  }
    44  
    45  func (_ *ItemTests) Extend() {
    46  	item := &Item{expires: time.Now().UnixNano() + 10}
    47  	item.Extend(time.Minute * 2)
    48  	Expect(item.Expires().Unix()).To.Equal(time.Now().Unix() + 120)
    49  }
    50  

View as plain text