mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
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
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -81,17 +80,14 @@ func TestSubmitWithdrawal(t *testing.T) {
|
||||
},
|
||||
}
|
||||
_, err = m.SubmitWithdrawal(t.Context(), req)
|
||||
if !errors.Is(err, common.ErrFunctionNotSupported) {
|
||||
t.Errorf("received %v, expected %v", err, common.ErrFunctionNotSupported)
|
||||
}
|
||||
assert.ErrorIs(t, err, common.ErrFunctionNotSupported)
|
||||
|
||||
req.Type = withdraw.Crypto
|
||||
req.Currency = currency.BTC
|
||||
req.Crypto.Address = "1337"
|
||||
_, err = m.SubmitWithdrawal(t.Context(), req)
|
||||
if !errors.Is(err, withdraw.ErrStrAddressNotWhiteListed) {
|
||||
t.Errorf("received %v, expected %v", err, withdraw.ErrStrAddressNotWhiteListed)
|
||||
}
|
||||
assert.ErrorIs(t, err, withdraw.ErrStrAddressNotWhiteListed)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
err = pm.Start(&wg)
|
||||
if err != nil {
|
||||
@@ -106,20 +102,14 @@ func TestSubmitWithdrawal(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = m.SubmitWithdrawal(t.Context(), req)
|
||||
if !errors.Is(err, withdraw.ErrStrExchangeNotSupportedByAddress) {
|
||||
t.Errorf("received %v, expected %v", err, withdraw.ErrStrExchangeNotSupportedByAddress)
|
||||
}
|
||||
assert.ErrorIs(t, err, withdraw.ErrStrExchangeNotSupportedByAddress)
|
||||
|
||||
adds[0].SupportedExchanges = withdrawManagerTestExchangeName
|
||||
_, err = m.SubmitWithdrawal(t.Context(), req)
|
||||
if !errors.Is(err, exchange.ErrAuthenticationSupportNotEnabled) {
|
||||
t.Errorf("received '%v', expected '%v'", err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
}
|
||||
assert.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
|
||||
_, err = m.SubmitWithdrawal(t.Context(), nil)
|
||||
if !errors.Is(err, withdraw.ErrRequestCannotBeNil) {
|
||||
t.Errorf("received %v, expected %v", err, withdraw.ErrRequestCannotBeNil)
|
||||
}
|
||||
assert.ErrorIs(t, err, withdraw.ErrRequestCannotBeNil)
|
||||
|
||||
m.isDryRun = true
|
||||
_, err = m.SubmitWithdrawal(t.Context(), req)
|
||||
@@ -137,9 +127,7 @@ func TestWithdrawEventByID(t *testing.T) {
|
||||
ID: withdraw.DryRunID,
|
||||
}
|
||||
_, err = m.WithdrawalEventByID(withdraw.DryRunID.String())
|
||||
if !errors.Is(err, ErrWithdrawRequestNotFound) {
|
||||
t.Errorf("received %v, expected %v", err, ErrWithdrawRequestNotFound)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrWithdrawRequestNotFound)
|
||||
|
||||
withdraw.Cache.Add(withdraw.DryRunID.String(), tempResp)
|
||||
v, err := m.WithdrawalEventByID(withdraw.DryRunID.String())
|
||||
@@ -159,18 +147,10 @@ func TestWithdrawalEventByExchange(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = (*WithdrawManager)(nil).WithdrawalEventByExchange("xxx", 0)
|
||||
if !errors.Is(err, ErrNilSubsystem) {
|
||||
t.Errorf("received: %v but expected: %v",
|
||||
err,
|
||||
ErrNilSubsystem)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilSubsystem)
|
||||
|
||||
_, err = m.WithdrawalEventByExchange("xxx", 0)
|
||||
if !errors.Is(err, ErrExchangeNotFound) {
|
||||
t.Errorf("received: %v but expected: %v",
|
||||
err,
|
||||
ErrExchangeNotFound)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrExchangeNotFound)
|
||||
}
|
||||
|
||||
func TestWithdrawEventByDate(t *testing.T) {
|
||||
@@ -182,18 +162,10 @@ func TestWithdrawEventByDate(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = (*WithdrawManager)(nil).WithdrawEventByDate("xxx", time.Now(), time.Now(), 1)
|
||||
if !errors.Is(err, ErrNilSubsystem) {
|
||||
t.Errorf("received: %v but expected: %v",
|
||||
err,
|
||||
ErrNilSubsystem)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilSubsystem)
|
||||
|
||||
_, err = m.WithdrawEventByDate("xxx", time.Now(), time.Now(), 1)
|
||||
if !errors.Is(err, ErrExchangeNotFound) {
|
||||
t.Errorf("received: %v but expected: %v",
|
||||
err,
|
||||
ErrExchangeNotFound)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrExchangeNotFound)
|
||||
}
|
||||
|
||||
func TestWithdrawalEventByExchangeID(t *testing.T) {
|
||||
@@ -205,16 +177,8 @@ func TestWithdrawalEventByExchangeID(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = (*WithdrawManager)(nil).WithdrawalEventByExchangeID("xxx", "xxx")
|
||||
if !errors.Is(err, ErrNilSubsystem) {
|
||||
t.Errorf("received: %v but expected: %v",
|
||||
err,
|
||||
ErrNilSubsystem)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilSubsystem)
|
||||
|
||||
_, err = m.WithdrawalEventByExchangeID("xxx", "xxx")
|
||||
if !errors.Is(err, ErrExchangeNotFound) {
|
||||
t.Errorf("received: %v but expected: %v",
|
||||
err,
|
||||
ErrExchangeNotFound)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrExchangeNotFound)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user