1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-16 04:24:56 +02:00

abi/cache_test.go: use redismock.

This commit is contained in:
Henrik Hautakoski 2023-01-13 14:39:07 +01:00
parent bcf55f1c12
commit d825f3bc50

View file

@ -7,7 +7,7 @@ import (
eos "github.com/eoscanada/eos-go"
redis_cache "github.com/go-redis/cache/v8"
"github.com/go-redis/redis/v8"
"github.com/go-redis/redismock/v8"
"github.com/stretchr/testify/assert"
)
@ -73,8 +73,10 @@ var abiString = `
`
func TestGetSet(t *testing.T) {
client, mock := redismock.NewClientMock()
c := NewCache("abi.cache.test", &redis_cache.Options{
Redis: redis.NewClient(&redis.Options{}),
Redis: client,
// Cache 10k keys for 1 minute.
LocalCache: redis_cache.NewTinyLFU(10000, time.Minute),
})
@ -82,6 +84,10 @@ func TestGetSet(t *testing.T) {
abi, err := eos.NewABI(strings.NewReader(abiString))
assert.NoError(t, err)
bytes, _ := c.c.Marshal(*abi)
mock.ExpectSet("abi.cache.test.testaccount", bytes, time.Minute).SetVal("OK")
err = c.Set("testaccount", abi, time.Minute)
assert.NoError(t, err)
@ -139,8 +145,10 @@ func TestGetSet(t *testing.T) {
}
func TestCacheMiss(t *testing.T) {
client, _ := redismock.NewClientMock()
c := NewCache("abi.cache.test", &redis_cache.Options{
Redis: redis.NewClient(&redis.Options{}),
Redis: client,
// Cache 10k keys for 1 minute.
LocalCache: redis_cache.NewTinyLFU(10000, time.Minute),
})