Compare commits

...

1 Commits

Author SHA1 Message Date
Pyroo ead796d7c2 test(storage-listx): add listx test 2021-11-27 21:38:01 +08:00
1 changed files with 47 additions and 0 deletions

47
storage/dao/listx_test.go Normal file
View File

@ -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"})
}