mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 15:10:54 +00:00
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
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/backtester/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -85,14 +87,10 @@ func TestLoadDataCandles(t *testing.T) {
|
||||
database.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
|
||||
testhelpers.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
|
||||
conn, err := testhelpers.ConnectToDatabase(&dbConfg)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received '%v' expected '%v'", err, nil)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
err = exchangeDB.InsertMany([]exchangeDB.Details{{Name: testExchange}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
dStart := time.Date(2020, 1, 0, 0, 0, 0, 0, time.UTC)
|
||||
dInsert := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
dEnd := time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||
@@ -115,14 +113,10 @@ func TestLoadDataCandles(t *testing.T) {
|
||||
},
|
||||
}
|
||||
_, err = gctkline.StoreInDatabase(data, true)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = LoadData(dStart, dEnd, gctkline.FifteenMin.Duration(), exch, common.DataCandle, p, a, false)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
if err = conn.SQL.Close(); err != nil {
|
||||
t.Error(err)
|
||||
@@ -160,9 +154,7 @@ func TestLoadDataTrades(t *testing.T) {
|
||||
database.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
|
||||
testhelpers.MigrationDir = filepath.Join("..", "..", "..", "..", "database", "migrations")
|
||||
conn, err := testhelpers.ConnectToDatabase(&dbConfg)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received '%v' expected '%v'", err, nil)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
err = exchangeDB.InsertMany([]exchangeDB.Details{{Name: testExchange}})
|
||||
if err != nil {
|
||||
@@ -183,14 +175,10 @@ func TestLoadDataTrades(t *testing.T) {
|
||||
Side: gctorder.Buy.String(),
|
||||
Timestamp: dInsert,
|
||||
})
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = LoadData(dStart, dEnd, gctkline.FifteenMin.Duration(), exch, common.DataTrade, p, a, false)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
if err = conn.SQL.Close(); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user