Files
gocryptotrader/backtester/data/kline/csv/csv_test.go
Adrian Gallagher a5b638bfb7 GHA: Add additional checks for common issues (#1922)
* GHA, tests: Add additional checks for common issues

These checks include:
- Ensuring that all testify funcs use their formatted variants (e.g., `assert.Equalf(t, expected, actual)` instead of `assert.Equal(t, expected, actual)`).
- Replacing `%s` with %q
- Enforcing consistent usage of should/must wording for testify assert/require messages

* Add support for checking backticked string format specifiers and fix issues

* tests: Fix error comparisons

* tests: Replace errors.Is(err, nil) usage with testify and automate check

* refactor: Rename ExtractPort to ExtractPortOrDefault

* tests: Replace assert with require for error handling in multiple test files

* tests: Replace assert with require for error handling and improve assertions in data tests

* tests: Fix typo in assertion message for StreamVol test

* OKX: Fix GetOpenInterestAndVolumeStrike test with instrument selection and improved assertions

* OKX: Revert intentional error check

* Improve error message for expiry time check in GetOpenInterestAndVolumeStrike test
2025-05-28 12:26:51 +10:00

75 lines
1.7 KiB
Go

package csv
import (
"errors"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
)
const testExchange = "binance"
func TestLoadDataCandles(t *testing.T) {
exch := testExchange
a := asset.Spot
p := currency.NewBTCUSDT()
_, err := LoadData(
common.DataCandle,
filepath.Join("..", "..", "..", "..", "testdata", "binance_BTCUSDT_24h_2019_01_01_2020_01_01.csv"),
exch,
gctkline.FifteenMin.Duration(),
p,
a,
false)
assert.NoError(t, err)
}
func TestLoadDataTrades(t *testing.T) {
exch := testExchange
a := asset.Spot
p := currency.NewBTCUSDT()
_, err := LoadData(
common.DataTrade,
filepath.Join("..", "..", "..", "..", "testdata", "binance_BTCUSDT_24h-trades_2020_11_16.csv"),
exch,
gctkline.FifteenMin.Duration(),
p,
a,
false)
assert.NoError(t, err)
}
func TestLoadDataInvalid(t *testing.T) {
exch := testExchange
a := asset.Spot
p := currency.NewBTCUSDT()
_, err := LoadData(
-1,
filepath.Join("..", "..", "..", "..", "testdata", "binance_BTCUSDT_24h-trades_2020_11_16.csv"),
exch,
gctkline.FifteenMin.Duration(),
p,
a,
false)
if !errors.Is(err, common.ErrInvalidDataType) {
t.Errorf("received: %v, expected: %v", err, common.ErrInvalidDataType)
}
_, err = LoadData(
-1,
filepath.Join("..", "..", "..", "..", "testdata", "binance_BTCUSDT_24h-trades_2020_11_16.csv"),
exch,
gctkline.FifteenMin.Duration(),
p,
a,
true)
if !errors.Is(err, errNoUSDData) {
t.Errorf("received: %v, expected: %v", err, errNoUSDData)
}
}