mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +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:
@@ -2,7 +2,6 @@ package gct
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -10,8 +9,8 @@ import (
|
||||
"testing"
|
||||
|
||||
objects "github.com/d5/tengo/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
@@ -102,45 +101,29 @@ var (
|
||||
|
||||
ctx = &gct.Context{}
|
||||
|
||||
tv = objects.TrueValue
|
||||
fv = objects.FalseValue
|
||||
errTestFailed = errors.New("test failed")
|
||||
tv = objects.TrueValue
|
||||
fv = objects.FalseValue
|
||||
)
|
||||
|
||||
func TestExchangeOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeOrderbook(ctx, exch, currencyPair, delimiter, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = gct.ExchangeOrderbook(ctx, exchError, currencyPair, delimiter, assetType)
|
||||
if err != nil && errors.Is(err, errTestFailed) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = gct.ExchangeOrderbook()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
}
|
||||
|
||||
func TestExchangeTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeTicker(ctx, exch, currencyPair, delimiter, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = gct.ExchangeTicker(ctx, exchError, currencyPair, delimiter, assetType)
|
||||
if err != nil && errors.Is(err, errTestFailed) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = gct.ExchangeTicker()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
}
|
||||
|
||||
func TestExchangeExchanges(t *testing.T) {
|
||||
@@ -161,27 +144,19 @@ func TestExchangeExchanges(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = gct.ExchangeExchanges()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
}
|
||||
|
||||
func TestExchangePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangePairs(exch, tv, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = gct.ExchangePairs(exchError, tv, assetType)
|
||||
if err != nil && errors.Is(err, errTestFailed) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = gct.ExchangePairs()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
}
|
||||
|
||||
func TestExchangeAccountInfo(t *testing.T) {
|
||||
@@ -199,26 +174,18 @@ func TestExchangeOrderQuery(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := gct.ExchangeOrderQuery()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
|
||||
_, err = gct.ExchangeOrderQuery(ctx, exch, orderID)
|
||||
if err != nil && err != common.ErrNotYetImplemented {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestExchangeOrderCancel(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeOrderCancel()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
_, err = gct.ExchangeOrderCancel(ctx, exch, orderID, currencyPair, assetType)
|
||||
if err != nil && err != common.ErrNotYetImplemented {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestExchangeOrderSubmit(t *testing.T) {
|
||||
@@ -251,66 +218,43 @@ func TestExchangeOrderSubmit(t *testing.T) {
|
||||
|
||||
func TestAllModuleNames(t *testing.T) {
|
||||
t.Parallel()
|
||||
x := gct.AllModuleNames()
|
||||
xType := reflect.TypeOf(x).Kind()
|
||||
if xType != reflect.Slice {
|
||||
t.Errorf("AllModuleNames() should return slice instead received: %v", x)
|
||||
}
|
||||
assert.IsType(t, []string{}, gct.AllModuleNames(), "AllModuleNames should return a slice of strings")
|
||||
}
|
||||
|
||||
func TestExchangeDepositAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeDepositAddress()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
|
||||
currCode := &objects.String{Value: "BTC"}
|
||||
chain := &objects.String{Value: ""}
|
||||
_, err = gct.ExchangeDepositAddress(exch, currCode, chain)
|
||||
if err != nil && err.Error() != "deposit address store is nil" {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestExchangeWithdrawCrypto(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeWithdrawCrypto()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
|
||||
currCode := &objects.String{Value: "BTC"}
|
||||
desc := &objects.String{Value: "HELLO"}
|
||||
address := &objects.String{Value: "0xTHISISALEGITBTCADDRESSS"}
|
||||
amount := &objects.Float{Value: 1.0}
|
||||
|
||||
_, err = gct.ExchangeWithdrawCrypto(ctx,
|
||||
exch,
|
||||
currCode,
|
||||
address,
|
||||
address,
|
||||
amount,
|
||||
amount,
|
||||
desc)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = gct.ExchangeWithdrawCrypto(ctx, exch, currCode, address, address, amount, amount, desc)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestExchangeWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeWithdrawFiat()
|
||||
if !errors.Is(err, objects.ErrWrongNumArguments) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
|
||||
currCode := &objects.String{Value: "TEST"}
|
||||
amount := &objects.Float{Value: 1.0}
|
||||
desc := &objects.String{Value: "2"}
|
||||
bankID := &objects.String{Value: "3!"}
|
||||
_, err = gct.ExchangeWithdrawFiat(ctx, exch, currCode, desc, amount, bankID)
|
||||
if err != nil && err.Error() != "exchange Bitstamp bank details not found for TEST" {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user