forked from p93542168/wheat-cache
test(storage-listx): add listx test
This commit is contained in:
parent
953daca82c
commit
ead796d7c2
|
@ -0,0 +1,47 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitee.com/wheat-os/wheatCache/pkg/lru"
|
||||
"gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDao_LPush_LPop(t *testing.T) {
|
||||
baseKey := proto.NewBaseKey("s")
|
||||
lru := lru.NewLRUCache()
|
||||
dao := NewDao(lru)
|
||||
|
||||
_, err := dao.LPush(baseKey, []string{"abc", "bcd"})
|
||||
require.NoError(t, err)
|
||||
_, err = dao.LPush(baseKey, []string{"a", "b"})
|
||||
require.NoError(t, err)
|
||||
_, err = dao.LPush(baseKey, []string{"c", "d"})
|
||||
require.NoError(t, err)
|
||||
resp, err := dao.LPop(baseKey, 5)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, resp.Results, []string{"d", "b", "bcd", "abc"})
|
||||
_, err = dao.LPush(baseKey, []string{"a", "b"})
|
||||
require.NoError(t, err)
|
||||
resp, err = dao.LPop(baseKey, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, resp.Results, []string{"b"})
|
||||
_, err = dao.LPush(baseKey, []string{"d"})
|
||||
require.NoError(t, err)
|
||||
resp, err = dao.LPop(baseKey, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, resp.Results, []string{})
|
||||
// resp, err = dao.LPop(baseKey, 1)
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, resp.Results, []string{"bcd"})
|
||||
// resp, err = dao.LPop(baseKey, 0)
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, resp.Results, []string{})
|
||||
|
||||
// _, err = dao.LPush(baseKey, []string{"b"})
|
||||
// require.NoError(t, err)
|
||||
// resp, err = dao.LPop(baseKey, 3)
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, resp.Results, []string{"a", "b", "abc"})
|
||||
}
|
Loading…
Reference in New Issue