mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 07:26:47 +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/atomic"
|
||||
"testing"
|
||||
|
||||
@@ -17,14 +16,10 @@ import (
|
||||
func TestSetupEventManager(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := setupEventManager(nil, nil, 0, false)
|
||||
if !errors.Is(err, errNilComManager) {
|
||||
t.Errorf("error '%v', expected '%v'", err, errNilComManager)
|
||||
}
|
||||
assert.ErrorIs(t, err, errNilComManager)
|
||||
|
||||
_, err = setupEventManager(&CommunicationManager{}, nil, 0, false)
|
||||
if !errors.Is(err, errNilExchangeManager) {
|
||||
t.Errorf("error '%v', expected '%v'", err, errNilExchangeManager)
|
||||
}
|
||||
assert.ErrorIs(t, err, errNilExchangeManager)
|
||||
|
||||
m, err := setupEventManager(&CommunicationManager{}, &ExchangeManager{}, 0, false)
|
||||
require.NoError(t, err)
|
||||
@@ -45,15 +40,11 @@ func TestEventManagerStart(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = m.Start()
|
||||
if !errors.Is(err, ErrSubSystemAlreadyStarted) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemAlreadyStarted)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrSubSystemAlreadyStarted)
|
||||
|
||||
m = nil
|
||||
err = m.Start()
|
||||
if !errors.Is(err, ErrNilSubsystem) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrNilSubsystem)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilSubsystem)
|
||||
}
|
||||
|
||||
func TestEventManagerIsRunning(t *testing.T) {
|
||||
@@ -89,14 +80,11 @@ func TestEventManagerStop(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = m.Stop()
|
||||
if !errors.Is(err, ErrSubSystemNotStarted) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemNotStarted)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrSubSystemNotStarted)
|
||||
|
||||
m = nil
|
||||
err = m.Stop()
|
||||
if !errors.Is(err, ErrNilSubsystem) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrNilSubsystem)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilSubsystem)
|
||||
}
|
||||
|
||||
func TestEventManagerAdd(t *testing.T) {
|
||||
@@ -106,16 +94,14 @@ func TestEventManagerAdd(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = m.Add("", "", EventConditionParams{}, currency.NewPair(currency.BTC, currency.USDC), asset.Spot, "")
|
||||
if !errors.Is(err, ErrSubSystemNotStarted) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemNotStarted)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrSubSystemNotStarted)
|
||||
|
||||
err = m.Start()
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = m.Add("", "", EventConditionParams{}, currency.NewPair(currency.BTC, currency.USDC), asset.Spot, "")
|
||||
if !errors.Is(err, errExchangeDisabled) {
|
||||
t.Errorf("error '%v', expected '%v'", err, errExchangeDisabled)
|
||||
}
|
||||
assert.ErrorIs(t, err, errExchangeDisabled)
|
||||
|
||||
exch, err := em.NewExchangeByName(testExchange)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -125,9 +111,7 @@ func TestEventManagerAdd(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = m.Add(testExchange, "", EventConditionParams{}, currency.NewPair(currency.BTC, currency.USDC), asset.Spot, "")
|
||||
if !errors.Is(err, errInvalidItem) {
|
||||
t.Errorf("error '%v', expected '%v'", err, errInvalidItem)
|
||||
}
|
||||
assert.ErrorIs(t, err, errInvalidItem)
|
||||
|
||||
cond := EventConditionParams{
|
||||
Condition: ConditionGreaterThan,
|
||||
@@ -135,9 +119,7 @@ func TestEventManagerAdd(t *testing.T) {
|
||||
OrderbookAmount: 1337,
|
||||
}
|
||||
_, err = m.Add(testExchange, ItemPrice, cond, currency.NewPair(currency.BTC, currency.USDC), asset.Spot, "")
|
||||
if !errors.Is(err, errInvalidAction) {
|
||||
t.Errorf("error '%v', expected '%v'", err, errInvalidAction)
|
||||
}
|
||||
assert.ErrorIs(t, err, errInvalidAction)
|
||||
|
||||
_, err = m.Add(testExchange, ItemPrice, cond, currency.NewPair(currency.BTC, currency.USDC), asset.Spot, ActionTest)
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user