mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
improve callID fallback for persistence
This commit is contained in:
parent
5d72ffaa0f
commit
027f1f01cf
|
@ -12,6 +12,15 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
type TestStructWithoutInstanceID struct {
|
||||
Symbol string
|
||||
}
|
||||
|
||||
func (s *TestStructWithoutInstanceID) ID() string {
|
||||
return "test-struct-no-instance-id"
|
||||
}
|
||||
|
||||
|
||||
type TestStruct struct {
|
||||
*Environment
|
||||
*Graceful
|
||||
|
@ -48,8 +57,16 @@ func preparePersistentServices() []service.PersistenceService {
|
|||
}
|
||||
|
||||
func Test_callID(t *testing.T) {
|
||||
id := callID(&TestStruct{})
|
||||
assert.NotEmpty(t, id)
|
||||
t.Run("default", func(t *testing.T) {
|
||||
id := callID(&TestStruct{})
|
||||
assert.NotEmpty(t, id)
|
||||
assert.Equal(t, "test-struct", id)
|
||||
})
|
||||
|
||||
t.Run("fallback", func(t *testing.T) {
|
||||
id := callID(&TestStructWithoutInstanceID{Symbol: "BTCUSDT"})
|
||||
assert.Equal(t, "test-struct-no-instance-id:BTCUSDT", id)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_loadPersistenceFields(t *testing.T) {
|
||||
|
|
|
@ -18,7 +18,17 @@ func callID(obj interface{}) string {
|
|||
ret := m.Call(nil)
|
||||
return ret[0].String()
|
||||
}
|
||||
return ""
|
||||
|
||||
if symbol, ok := isSymbolBasedStrategy(sv); ok {
|
||||
m := sv.MethodByName("ID")
|
||||
ret := m.Call(nil)
|
||||
return ret[0].String() + ":" + symbol
|
||||
}
|
||||
|
||||
// fallback to just ID
|
||||
m := sv.MethodByName("ID")
|
||||
ret := m.Call(nil)
|
||||
return ret[0].String() + ":"
|
||||
}
|
||||
|
||||
func isSymbolBasedStrategy(rs reflect.Value) (string, bool) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user