42 lines
890 B
Go
42 lines
890 B
Go
|
package service
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
|
||
|
"git.qtrade.icu/lychiyu/qbtrade/pkg/fixedpoint"
|
||
|
)
|
||
|
|
||
|
func TestRedisPersistentService(t *testing.T) {
|
||
|
redisService := NewRedisPersistenceService(&RedisPersistenceConfig{
|
||
|
Host: "127.0.0.1",
|
||
|
Port: "6379",
|
||
|
DB: 0,
|
||
|
})
|
||
|
assert.NotNil(t, redisService)
|
||
|
|
||
|
store := redisService.NewStore("qbtrade", "test")
|
||
|
assert.NotNil(t, store)
|
||
|
|
||
|
err := store.Reset()
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
var fp fixedpoint.Value
|
||
|
err = store.Load(fp)
|
||
|
assert.Error(t, err)
|
||
|
assert.EqualError(t, ErrPersistenceNotExists, err.Error())
|
||
|
|
||
|
fp = fixedpoint.NewFromFloat(3.1415)
|
||
|
err = store.Save(&fp)
|
||
|
assert.NoError(t, err, "should store value without error")
|
||
|
|
||
|
var fp2 fixedpoint.Value
|
||
|
err = store.Load(&fp2)
|
||
|
assert.NoError(t, err, "should load value without error")
|
||
|
assert.Equal(t, fp, fp2)
|
||
|
|
||
|
err = store.Reset()
|
||
|
assert.NoError(t, err)
|
||
|
}
|