switched from gspec -> expect
This commit is contained in:
@@ -1,25 +1,31 @@
|
||||
package ccache
|
||||
|
||||
import (
|
||||
"github.com/karlseguin/gspec"
|
||||
. "github.com/karlseguin/expect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCacheGCsTheOldestItems(t *testing.T) {
|
||||
spec := gspec.New(t)
|
||||
type CacheTests struct{}
|
||||
|
||||
func Test_Cache(t *testing.T) {
|
||||
Expectify(new(CacheTests), t)
|
||||
}
|
||||
|
||||
func (c *CacheTests) GCsTheOldestItems() {
|
||||
cache := New(Configure().ItemsToPrune(10))
|
||||
for i := 0; i < 500; i++ {
|
||||
cache.Set(strconv.Itoa(i), i, time.Minute)
|
||||
}
|
||||
//let the items get promoted (and added to our list)
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
cache.gc()
|
||||
spec.Expect(cache.Get("9")).ToBeNil()
|
||||
spec.Expect(cache.Get("10").(int)).ToEqual(10)
|
||||
Expect(cache.Get("9")).To.Equal(nil)
|
||||
Expect(cache.Get("10").(int)).To.Equal(10)
|
||||
}
|
||||
|
||||
func TestCachePromotedItemsDontGetPruned(t *testing.T) {
|
||||
spec := gspec.New(t)
|
||||
func (c *CacheTests) PromotedItemsDontGetPruned() {
|
||||
cache := New(Configure().ItemsToPrune(10).GetsPerPromote(1))
|
||||
for i := 0; i < 500; i++ {
|
||||
cache.Set(strconv.Itoa(i), i, time.Minute)
|
||||
@@ -28,13 +34,12 @@ func TestCachePromotedItemsDontGetPruned(t *testing.T) {
|
||||
cache.Get("9")
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
cache.gc()
|
||||
spec.Expect(cache.Get("9").(int)).ToEqual(9)
|
||||
spec.Expect(cache.Get("10")).ToBeNil()
|
||||
spec.Expect(cache.Get("11").(int)).ToEqual(11)
|
||||
Expect(cache.Get("9").(int)).To.Equal(9)
|
||||
Expect(cache.Get("10")).To.Equal(nil)
|
||||
Expect(cache.Get("11").(int)).To.Equal(11)
|
||||
}
|
||||
|
||||
func TestCacheTrackerDoesNotCleanupHeldInstance(t *testing.T) {
|
||||
spec := gspec.New(t)
|
||||
func (c *CacheTests) TrackerDoesNotCleanupHeldInstance() {
|
||||
cache := New(Configure().ItemsToPrune(10).Track())
|
||||
for i := 0; i < 10; i++ {
|
||||
cache.Set(strconv.Itoa(i), i, time.Minute)
|
||||
@@ -42,21 +47,20 @@ func TestCacheTrackerDoesNotCleanupHeldInstance(t *testing.T) {
|
||||
item := cache.TrackingGet("0")
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
cache.gc()
|
||||
spec.Expect(cache.Get("0").(int)).ToEqual(0)
|
||||
spec.Expect(cache.Get("1")).ToBeNil()
|
||||
Expect(cache.Get("0").(int)).To.Equal(0)
|
||||
Expect(cache.Get("1")).To.Equal(nil)
|
||||
item.Release()
|
||||
cache.gc()
|
||||
spec.Expect(cache.Get("0")).ToBeNil()
|
||||
Expect(cache.Get("0")).To.Equal(nil)
|
||||
}
|
||||
|
||||
func TestCacheRemovesOldestItemWhenFull(t *testing.T) {
|
||||
spec := gspec.New(t)
|
||||
func (c *CacheTests) RemovesOldestItemWhenFull() {
|
||||
cache := New(Configure().MaxItems(5).ItemsToPrune(1))
|
||||
for i := 0; i < 7; i++ {
|
||||
cache.Set(strconv.Itoa(i), i, time.Minute)
|
||||
}
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
spec.Expect(cache.Get("0")).ToBeNil()
|
||||
spec.Expect(cache.Get("1")).ToBeNil()
|
||||
spec.Expect(cache.Get("2").(int)).ToEqual(2)
|
||||
Expect(cache.Get("0")).To.Equal(nil)
|
||||
Expect(cache.Get("1")).To.Equal(nil)
|
||||
Expect(cache.Get("2").(int)).To.Equal(2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user