mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 15:10:40 +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:
@@ -3,7 +3,6 @@ package gateio
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -340,15 +339,13 @@ func TestAmendSpotOrder(t *testing.T) {
|
||||
_, err := g.AmendSpotOrder(t.Context(), "", getPair(t, asset.Spot), false, &PriceAndAmount{
|
||||
Price: 1000,
|
||||
})
|
||||
if !errors.Is(err, errInvalidOrderID) {
|
||||
t.Errorf("expecting %v, but found %v", errInvalidOrderID, err)
|
||||
}
|
||||
assert.ErrorIs(t, err, errInvalidOrderID)
|
||||
|
||||
_, err = g.AmendSpotOrder(t.Context(), "123", currency.EMPTYPAIR, false, &PriceAndAmount{
|
||||
Price: 1000,
|
||||
})
|
||||
if !errors.Is(err, currency.ErrCurrencyPairEmpty) {
|
||||
t.Errorf("expecting %v, but found %v", currency.ErrCurrencyPairEmpty, err)
|
||||
}
|
||||
assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
||||
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
|
||||
_, err = g.AmendSpotOrder(t.Context(), "123", getPair(t, asset.Spot), false, &PriceAndAmount{
|
||||
Price: 1000,
|
||||
@@ -513,13 +510,13 @@ func TestRetriveOneSingleLoanDetail(t *testing.T) {
|
||||
|
||||
func TestModifyALoan(t *testing.T) {
|
||||
t.Parallel()
|
||||
if _, err := g.ModifyALoan(t.Context(), "1234", &ModifyLoanRequestParam{
|
||||
_, err := g.ModifyALoan(t.Context(), "1234", &ModifyLoanRequestParam{
|
||||
Currency: currency.BTC,
|
||||
Side: "borrow",
|
||||
AutoRenew: false,
|
||||
}); !errors.Is(err, currency.ErrCurrencyPairEmpty) {
|
||||
t.Errorf("%s ModifyALoan() error %v", g.Name, err)
|
||||
}
|
||||
})
|
||||
assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
||||
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
|
||||
if _, err := g.ModifyALoan(t.Context(), "1234", &ModifyLoanRequestParam{
|
||||
Currency: currency.BTC,
|
||||
@@ -1608,15 +1605,13 @@ func TestGetUsersPositionSpecifiedUnderlying(t *testing.T) {
|
||||
|
||||
func TestGetSpecifiedContractPosition(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
_, err := g.GetSpecifiedContractPosition(t.Context(), currency.EMPTYPAIR)
|
||||
if err != nil && !errors.Is(err, errInvalidOrMissingContractParam) {
|
||||
t.Errorf("%s GetSpecifiedContractPosition() error expecting %v, but found %v", g.Name, errInvalidOrMissingContractParam, err)
|
||||
}
|
||||
assert.ErrorIs(t, err, errInvalidOrMissingContractParam)
|
||||
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
|
||||
_, err = g.GetSpecifiedContractPosition(t.Context(), getPair(t, asset.Options))
|
||||
if err != nil {
|
||||
t.Errorf("%s GetSpecifiedContractPosition() error expecting %v, but found %v", g.Name, errInvalidOrMissingContractParam, err)
|
||||
}
|
||||
assert.NoError(t, err, "GetSpecifiedContractPosition should not error")
|
||||
}
|
||||
|
||||
func TestGetUsersLiquidationHistoryForSpecifiedUnderlying(t *testing.T) {
|
||||
@@ -1661,13 +1656,13 @@ func TestCancelOptionOpenOrders(t *testing.T) {
|
||||
|
||||
func TestGetSingleOptionOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := g.GetSingleOptionOrder(t.Context(), "")
|
||||
assert.ErrorIs(t, err, errInvalidOrderID)
|
||||
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
if _, err := g.GetSingleOptionOrder(t.Context(), ""); err != nil && !errors.Is(errInvalidOrderID, err) {
|
||||
t.Errorf("%s GetSingleOptionorder() expecting %v, but found %v", g.Name, errInvalidOrderID, err)
|
||||
}
|
||||
if _, err := g.GetSingleOptionOrder(t.Context(), "1234"); err != nil {
|
||||
t.Errorf("%s GetSingleOptionOrder() error %v", g.Name, err)
|
||||
}
|
||||
|
||||
_, err = g.GetSingleOptionOrder(t.Context(), "1234")
|
||||
assert.NoError(t, err, "GetSingleOptionOrder should not error")
|
||||
}
|
||||
|
||||
func TestCancelSingleOrder(t *testing.T) {
|
||||
@@ -1688,11 +1683,9 @@ func TestGetMyOptionsTradingHistory(t *testing.T) {
|
||||
|
||||
func TestWithdrawCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
|
||||
_, err := g.WithdrawCurrency(t.Context(), WithdrawalRequestParam{})
|
||||
if err != nil && !errors.Is(err, errInvalidAmount) {
|
||||
t.Errorf("%s WithdrawCurrency() expecting error %v, but found %v", g.Name, errInvalidAmount, err)
|
||||
}
|
||||
assert.ErrorIs(t, err, errInvalidAmount)
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
|
||||
_, err = g.WithdrawCurrency(t.Context(), WithdrawalRequestParam{
|
||||
Currency: currency.BTC,
|
||||
Amount: 0.00000001,
|
||||
@@ -2563,14 +2556,10 @@ func TestUpdateOrderExecutionLimits(t *testing.T) {
|
||||
testexch.UpdatePairsOnce(t, g)
|
||||
|
||||
err := g.UpdateOrderExecutionLimits(t.Context(), 1336)
|
||||
if !errors.Is(err, asset.ErrNotSupported) {
|
||||
t.Fatalf("received %v, expected %v", err, asset.ErrNotSupported)
|
||||
}
|
||||
require.ErrorIs(t, err, asset.ErrNotSupported)
|
||||
|
||||
err = g.UpdateOrderExecutionLimits(t.Context(), asset.Options)
|
||||
if !errors.Is(err, common.ErrNotYetImplemented) {
|
||||
t.Fatalf("received %v, expected %v", err, common.ErrNotYetImplemented)
|
||||
}
|
||||
require.ErrorIs(t, err, common.ErrNotYetImplemented)
|
||||
|
||||
err = g.UpdateOrderExecutionLimits(t.Context(), asset.Spot)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user