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:
parent
bcf55f1c12
commit
d825f3bc50
1 changed files with 11 additions and 3 deletions
|
|
@ -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),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue