forked from p93542168/wheat-cache
141 lines
2.9 KiB
Go
141 lines
2.9 KiB
Go
package stringx
|
|
|
|
import (
|
|
"gitee.com/timedb/wheatCache/pkg/proto"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestStringSingle_Set(t *testing.T) {
|
|
s := NewStringSingle()
|
|
resp, err := s.Set(&proto.SetRequest{
|
|
Val: "189",
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "189")
|
|
i, err := s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, i.Result, "189")
|
|
s.Set(&proto.SetRequest{
|
|
Val: "1.25",
|
|
})
|
|
i, err = s.Get(&proto.GetRequest{})
|
|
require.Equal(t, i.Result, "1.25")
|
|
|
|
s.Set(&proto.SetRequest{
|
|
Val: "awdgiugaiuwdhoawd",
|
|
})
|
|
i, err = s.Get(&proto.GetRequest{})
|
|
require.Equal(t, i.Result, "awdgiugaiuwdhoawd")
|
|
}
|
|
|
|
func TestStringSingle_Add(t *testing.T) {
|
|
s := NewStringSingle()
|
|
_, err := s.Set(&proto.SetRequest{
|
|
Val: "135",
|
|
})
|
|
require.NoError(t, err)
|
|
s.Add(&proto.AddRequest{
|
|
Renewal: 9,
|
|
})
|
|
resp, err := s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "144")
|
|
|
|
// float
|
|
_, err = s.Set(&proto.SetRequest{
|
|
Val: "135.33",
|
|
})
|
|
require.NoError(t, err)
|
|
s.Add(&proto.AddRequest{
|
|
Renewal: 3,
|
|
})
|
|
resp, err = s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "138.33")
|
|
|
|
// string
|
|
_, err = s.Set(&proto.SetRequest{
|
|
Val: "awjdwad",
|
|
})
|
|
require.NoError(t, err)
|
|
_, err = s.Add(&proto.AddRequest{
|
|
Renewal: 3,
|
|
})
|
|
require.Error(t, err)
|
|
resp, err = s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "awjdwad")
|
|
}
|
|
|
|
func TestStringSingle_Reduce(t *testing.T) {
|
|
s := NewStringSingle()
|
|
_, err := s.Set(&proto.SetRequest{
|
|
Val: "135",
|
|
})
|
|
require.NoError(t, err)
|
|
s.Reduce(&proto.ReduceRequest{
|
|
Renewal: 5,
|
|
})
|
|
resp, err := s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "130")
|
|
|
|
// float
|
|
_, err = s.Set(&proto.SetRequest{
|
|
Val: "135.33",
|
|
})
|
|
require.NoError(t, err)
|
|
s.Reduce(&proto.ReduceRequest{
|
|
Renewal: 3,
|
|
})
|
|
resp, err = s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "132.33")
|
|
|
|
// string
|
|
_, err = s.Set(&proto.SetRequest{
|
|
Val: "awjdwad",
|
|
})
|
|
require.NoError(t, err)
|
|
_, err = s.Reduce(&proto.ReduceRequest{
|
|
Renewal: 3,
|
|
})
|
|
require.Error(t, err)
|
|
resp, err = s.Get(&proto.GetRequest{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, resp.Result, "awjdwad")
|
|
}
|
|
|
|
func TestStringSingle_Getbit(t *testing.T) {
|
|
s := NewStringSingle()
|
|
_, err := s.Setbit(&proto.SetbitRequest{
|
|
Offer: 1009,
|
|
Val: true,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
res, err := s.Getbit(&proto.GetbitRequest{
|
|
Offer: 1009,
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, res.Val, true)
|
|
res, err = s.Getbit(&proto.GetbitRequest{
|
|
Offer: 1008,
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, res.Val, false)
|
|
|
|
_, err = s.Setbit(&proto.SetbitRequest{
|
|
Offer: 1009,
|
|
Val: false,
|
|
})
|
|
|
|
res, err = s.Getbit(&proto.GetbitRequest{
|
|
Offer: 1009,
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, res.Val, false)
|
|
|
|
}
|