1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-07-04 12:03:41 +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" eos "github.com/eoscanada/eos-go"
redis_cache "github.com/go-redis/cache/v8" 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" "github.com/stretchr/testify/assert"
) )
@ -73,8 +73,10 @@ var abiString = `
` `
func TestGetSet(t *testing.T) { func TestGetSet(t *testing.T) {
client, mock := redismock.NewClientMock()
c := NewCache("abi.cache.test", &redis_cache.Options{ c := NewCache("abi.cache.test", &redis_cache.Options{
Redis: redis.NewClient(&redis.Options{}), Redis: client,
// Cache 10k keys for 1 minute. // Cache 10k keys for 1 minute.
LocalCache: redis_cache.NewTinyLFU(10000, time.Minute), LocalCache: redis_cache.NewTinyLFU(10000, time.Minute),
}) })
@ -82,6 +84,10 @@ func TestGetSet(t *testing.T) {
abi, err := eos.NewABI(strings.NewReader(abiString)) abi, err := eos.NewABI(strings.NewReader(abiString))
assert.NoError(t, err) 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) err = c.Set("testaccount", abi, time.Minute)
assert.NoError(t, err) assert.NoError(t, err)
@ -139,8 +145,10 @@ func TestGetSet(t *testing.T) {
} }
func TestCacheMiss(t *testing.T) { func TestCacheMiss(t *testing.T) {
client, _ := redismock.NewClientMock()
c := NewCache("abi.cache.test", &redis_cache.Options{ c := NewCache("abi.cache.test", &redis_cache.Options{
Redis: redis.NewClient(&redis.Options{}), Redis: client,
// Cache 10k keys for 1 minute. // Cache 10k keys for 1 minute.
LocalCache: redis_cache.NewTinyLFU(10000, time.Minute), LocalCache: redis_cache.NewTinyLFU(10000, time.Minute),
}) })