Files
gocryptotrader/backtester/plugins/strategies/loader_test.go
Adrian Gallagher 19b8957f3f codebase: Replace !errors.Is(err, target) with testify (#1931)
* tests: Replace !errors.Is(err, target) with testify equivalents

* codebase: Manual !errors.Is(err, target) replacements

* typo: Replace errMisMatchedEvent with errMismatchedEvent

* tests: Enhance error messages for better output

* tests: Refactor error assertions in various test cases to use require and improve clarity

* misc linter: Fix assert should wording

* tests: Simplify assertions in TestCreateSignals for clarity and conciseness

* tests: Enhance assertion message in TestCreateSignals
2025-06-10 16:29:57 +10:00

61 lines
1.8 KiB
Go

package strategies
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/backtester/data"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/portfolio"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/base"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/dollarcostaverage"
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/signal"
"github.com/thrasher-corp/gocryptotrader/backtester/funding"
)
func TestAddStrategies(t *testing.T) {
t.Parallel()
err := addStrategies(nil)
assert.ErrorIs(t, err, errNoStrategies)
err = addStrategies([]strategies.Handler{&dollarcostaverage.Strategy{}})
assert.ErrorIs(t, err, strategies.ErrStrategyAlreadyExists)
err = addStrategies([]strategies.Handler{&CustomStrategy{}})
assert.NoError(t, err)
}
type CustomStrategy struct {
base.Strategy
}
func (s *CustomStrategy) Name() string {
return "custom-strategy"
}
func (s *CustomStrategy) Description() string {
return "this is a demonstration of loading strategies via custom plugins"
}
func (s *CustomStrategy) SupportsSimultaneousProcessing() bool {
return true
}
func (s *CustomStrategy) OnSignal(d data.Handler, _ funding.IFundingTransferer, _ portfolio.Handler) (signal.Event, error) {
return s.createSignal(d)
}
func (s *CustomStrategy) OnSimultaneousSignals(_ []data.Handler, _ funding.IFundingTransferer, _ portfolio.Handler) ([]signal.Event, error) {
return nil, nil
}
func (s *CustomStrategy) createSignal(_ data.Handler) (*signal.Signal, error) {
return nil, nil
}
func (s *CustomStrategy) SetCustomSettings(map[string]any) error {
return nil
}
func (s *CustomStrategy) SetDefaults() {}