bbgo_origin/pkg/service/persistence_redis_test.go

42 lines
876 B
Go
Raw Normal View History

package service
2020-12-07 15:03:06 +00:00
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
func TestRedisPersistentService(t *testing.T) {
2021-02-20 17:01:39 +00:00
redisService := NewRedisPersistenceService(&RedisPersistenceConfig{
2021-01-21 07:10:40 +00:00
Host: "127.0.0.1",
Port: "6379",
DB: 0,
2020-12-07 15:03:06 +00:00
})
assert.NotNil(t, redisService)
store := redisService.NewStore("bbgo", "test")
assert.NotNil(t, store)
err := store.Reset()
assert.NoError(t, err)
var fp fixedpoint.Value
err = store.Load(fp)
assert.Error(t, err)
2021-01-21 07:07:19 +00:00
assert.EqualError(t, ErrPersistenceNotExists, err.Error())
2020-12-07 15:03:06 +00:00
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)
}