add State PlainText method test

This commit is contained in:
c9s 2021-05-16 00:59:57 +08:00
parent 2652bee83b
commit 933765defb
2 changed files with 26 additions and 1 deletions

View File

@ -36,6 +36,12 @@ func (s *State) IsOver24Hours() bool {
return time.Now().Sub(time.Unix(s.Since, 0)) >= 24*time.Hour return time.Now().Sub(time.Unix(s.Since, 0)) >= 24*time.Hour
} }
func (s *State) PlainText() string {
return util.Render(`{{ .Asset }} transfer stats:
daily number of transfers: {{ .DailyNumberOfTransfers }}
daily amount of transfers {{ .DailyAmountOfTransfers.Float64 }}`, s)
}
func (s *State) SlackAttachment() slack.Attachment { func (s *State) SlackAttachment() slack.Attachment {
return slack.Attachment{ return slack.Attachment{
// Pretext: "", // Pretext: "",
@ -276,7 +282,7 @@ func (s *Strategy) SaveState() {
log.WithError(err).Errorf("can not save state: %+v", s.state) log.WithError(err).Errorf("can not save state: %+v", s.state)
} else { } else {
log.Infof("%s %s state is saved: %+v", ID, s.Asset, s.state) log.Infof("%s %s state is saved: %+v", ID, s.Asset, s.state)
s.Notifiability.Notify("%s %s state is saved => %f", ID, s.Asset, s.state) s.Notifiability.Notify("%s %s state is saved", ID, s.Asset, s.state)
} }
} }

View File

@ -0,0 +1,19 @@
package xbalance
import (
"testing"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/stretchr/testify/assert"
)
func TestState_PlainText(t *testing.T) {
var state = State{
Asset: "USDT",
DailyNumberOfTransfers: 1,
DailyAmountOfTransfers: fixedpoint.NewFromFloat(1000.0),
Since: 0,
}
assert.Equal(t, "USDT transfer stats:\ndaily number of transfers: 1\ndaily amount of transfers 1000", state.PlainText())
}