mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 15:10:44 +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:
@@ -86,7 +86,7 @@ func (e *ExecutionLimits) LoadLimits(levels []MinMaxLevel) error {
|
||||
|
||||
for x := range levels {
|
||||
if !levels[x].Asset.IsValid() {
|
||||
return fmt.Errorf("cannot load levels for '%s': %w", levels[x].Asset, asset.ErrNotSupported)
|
||||
return fmt.Errorf("cannot load levels for %q: %w", levels[x].Asset, asset.ErrNotSupported)
|
||||
}
|
||||
m1, ok := e.m[levels[x].Asset]
|
||||
if !ok {
|
||||
|
||||
@@ -1108,7 +1108,7 @@ func TestValidationOnOrderTypes(t *testing.T) {
|
||||
|
||||
modifyOrder.ClientOrderID = "1337"
|
||||
require.NoError(t, modifyOrder.Validate())
|
||||
require.Error(t, modifyOrder.Validate(validate.Check(func() error { return errors.New("this should error") })))
|
||||
require.Error(t, modifyOrder.Validate(validate.Check(func() error { return errors.New("this must error") })))
|
||||
require.NoError(t, modifyOrder.Validate(validate.Check(func() error { return nil })))
|
||||
}
|
||||
|
||||
@@ -1357,7 +1357,7 @@ func TestDetail_Copy(t *testing.T) {
|
||||
}
|
||||
for i := range d {
|
||||
r := d[i].Copy()
|
||||
assert.True(t, reflect.DeepEqual(d[i], r), "[%d] Copy does not contain same elements, expected: %v\ngot:%v", i, d[i], r)
|
||||
assert.Truef(t, reflect.DeepEqual(d[i], r), "[%d] Copy does not contain same elements, expected: %v\ngot:%v", i, d[i], r)
|
||||
if len(d[i].Trades) > 0 {
|
||||
assert.NotSamef(t, &d[i].Trades[0], &r.Trades[0], "[%d]Trades point to the same data elements", i)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (s *Submit) Validate(requirements protocol.TradingRequirements, opt ...vali
|
||||
}
|
||||
|
||||
if !s.AssetType.IsValid() {
|
||||
return fmt.Errorf("'%s' %w", s.AssetType, asset.ErrNotSupported)
|
||||
return fmt.Errorf("%q %w", s.AssetType, asset.ErrNotSupported)
|
||||
}
|
||||
|
||||
if !IsValidOrderSubmissionSide(s.Side) {
|
||||
@@ -1076,7 +1076,7 @@ func StringToOrderSide(side string) (Side, error) {
|
||||
case AnySide.String():
|
||||
return AnySide, nil
|
||||
default:
|
||||
return UnknownSide, fmt.Errorf("'%s' %w", side, ErrSideIsInvalid)
|
||||
return UnknownSide, fmt.Errorf("%q %w", side, ErrSideIsInvalid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1193,7 +1193,7 @@ func StringToOrderStatus(status string) (Status, error) {
|
||||
case STP.String(), "STP":
|
||||
return STP, nil
|
||||
default:
|
||||
return UnknownStatus, fmt.Errorf("'%s' %w", status, errUnrecognisedOrderStatus)
|
||||
return UnknownStatus, fmt.Errorf("%q %w", status, errUnrecognisedOrderStatus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestTimeInForceIs(t *testing.T) {
|
||||
}
|
||||
for tif, exps := range tifValuesMap {
|
||||
for _, v := range exps {
|
||||
require.Truef(t, tif.Is(v), "%s should be %s", tif, v)
|
||||
assert.Truef(t, tif.Is(v), "%s should be %s", tif, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user