test(dao): remove dao test

This commit is contained in:
bandl 2021-10-27 23:55:36 +08:00
parent 54520cb033
commit b4c3cc5a86
1 changed files with 0 additions and 84 deletions

View File

@ -1,89 +1,5 @@
package dao
import (
"testing"
_ "gitee.com/timedb/wheatCache/conf"
"gitee.com/timedb/wheatCache/pkg/lru"
"gitee.com/timedb/wheatCache/pkg/proto"
"github.com/stretchr/testify/require"
)
func mockData(t *testing.T, d *Dao) {
values := []string{"1", "1.3", "abcdefg"}
for _, val := range values {
key := &proto.BaseKey{
Key: val,
}
_, err := d.Set(key, val)
require.NoError(t, err)
}
}
func TestDao_Set(t *testing.T) {
lruCache := lru.NewLRUCache()
dao := NewDao(lruCache)
key := &proto.BaseKey{
Key: "abc",
}
res, err := dao.Set(key, "abc")
require.NoError(t, err)
require.Equal(t, res, "abc")
res, err = dao.Get(key)
require.NoError(t, err)
require.Equal(t, res, "abc")
}
func TestDao_Add(t *testing.T) {
lruCache := lru.NewLRUCache()
dao := NewDao(lruCache)
mockData(t, dao)
resp, err := dao.Add(&proto.BaseKey{Key: "1"}, 2)
require.NoError(t, err)
require.Equal(t, resp, "3")
resp, err = dao.Add(&proto.BaseKey{Key: "1.3"}, 2)
require.NoError(t, err)
require.Equal(t, resp, "3.30")
_, err = dao.Add(&proto.BaseKey{Key: "abcdefg"}, 2)
require.Error(t, err)
}
func TestDao_Reduce(t *testing.T) {
lruCache := lru.NewLRUCache()
dao := NewDao(lruCache)
mockData(t, dao)
resp, err := dao.Reduce(&proto.BaseKey{Key: "1"}, 2)
require.NoError(t, err)
require.Equal(t, resp, "-1")
resp, err = dao.Reduce(&proto.BaseKey{Key: "1.3"}, 2)
require.NoError(t, err)
require.Equal(t, resp, "-0.70")
_, err = dao.Reduce(&proto.BaseKey{Key: "abcdefg"}, 2)
require.Error(t, err)
}
func TestDao_Setbit(t *testing.T) {
lruCache := lru.NewLRUCache()
dao := NewDao(lruCache)
key := &proto.BaseKey{
Key: "abc",
}
err := dao.Setbit(key, true, 3089)
require.NoError(t, err)
re, err := dao.GetBit(key, 3089)
require.NoError(t, err)
require.Equal(t, re, true)
}