github.com/vicanso/lru-ttl@v1.5.1/ring_test.go (about)

     1  package lruttl
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestRingCache(t *testing.T) {
    12  	assert := assert.New(t)
    13  
    14  	ringCache := NewRing(RingCacheParams{
    15  		Size:       10,
    16  		MaxEntries: 1000,
    17  		DefaultTTL: time.Minute,
    18  	})
    19  
    20  	key := "test"
    21  	c := ringCache.Get(key)
    22  	assert.NotNil(c)
    23  	assert.Equal(c, ringCache.Get(key))
    24  
    25  	for i := 0; i < 1000; i++ {
    26  		str := strconv.Itoa(int(time.Now().UnixNano()))
    27  		assert.NotNil(ringCache.Get(str))
    28  	}
    29  }