mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +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 database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -18,33 +17,25 @@ func TestSetConfig(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = inst.SetConfig(nil)
|
||||
if !errors.Is(err, ErrNilConfig) {
|
||||
t.Errorf("received %v, expected %v", err, ErrNilConfig)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilConfig)
|
||||
|
||||
inst = nil
|
||||
err = inst.SetConfig(&Config{})
|
||||
if !errors.Is(err, ErrNilInstance) {
|
||||
t.Errorf("received %v, expected %v", err, ErrNilInstance)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilInstance)
|
||||
}
|
||||
|
||||
func TestSetSQLiteConnection(t *testing.T) {
|
||||
t.Parallel()
|
||||
inst := &Instance{}
|
||||
err := inst.SetSQLiteConnection(nil)
|
||||
if !errors.Is(err, errNilSQL) {
|
||||
t.Errorf("received %v, expected %v", err, errNilSQL)
|
||||
}
|
||||
assert.ErrorIs(t, err, errNilSQL)
|
||||
|
||||
err = inst.SetSQLiteConnection(&sql.DB{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
inst = nil
|
||||
err = inst.SetSQLiteConnection(nil)
|
||||
if !errors.Is(err, ErrNilInstance) {
|
||||
t.Errorf("received %v, expected %v", err, ErrNilInstance)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilInstance)
|
||||
}
|
||||
|
||||
func TestSetPostgresConnection(t *testing.T) {
|
||||
@@ -142,19 +133,16 @@ func TestPing(t *testing.T) {
|
||||
|
||||
inst.SQL = nil
|
||||
err = inst.Ping()
|
||||
if !errors.Is(err, errNilSQL) {
|
||||
t.Errorf("received %v, expected %v", err, errNilSQL)
|
||||
}
|
||||
assert.ErrorIs(t, err, errNilSQL)
|
||||
|
||||
inst.SetConnected(false)
|
||||
err = inst.Ping()
|
||||
if !errors.Is(err, ErrDatabaseNotConnected) {
|
||||
t.Errorf("received %v, expected %v", err, ErrDatabaseNotConnected)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrDatabaseNotConnected)
|
||||
|
||||
inst = nil
|
||||
err = inst.Ping()
|
||||
if !errors.Is(err, ErrNilInstance) {
|
||||
t.Errorf("received %v, expected %v", err, ErrNilInstance)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilInstance)
|
||||
|
||||
err = con.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -166,9 +154,7 @@ func TestGetSQL(t *testing.T) {
|
||||
t.Parallel()
|
||||
inst := &Instance{}
|
||||
_, err := inst.GetSQL()
|
||||
if !errors.Is(err, errNilSQL) {
|
||||
t.Errorf("received %v, expected %v", err, errNilSQL)
|
||||
}
|
||||
assert.ErrorIs(t, err, errNilSQL)
|
||||
|
||||
databaseFullLocation := filepath.Join(DB.DataPath, "TestGetSQL")
|
||||
con, err := sql.Open("sqlite3", databaseFullLocation)
|
||||
@@ -182,7 +168,5 @@ func TestGetSQL(t *testing.T) {
|
||||
|
||||
inst = nil
|
||||
_, err = inst.GetSQL()
|
||||
if !errors.Is(err, ErrNilInstance) {
|
||||
t.Errorf("received %v, expected %v", err, ErrNilInstance)
|
||||
}
|
||||
assert.ErrorIs(t, err, ErrNilInstance)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package candle
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/drivers"
|
||||
@@ -245,20 +246,11 @@ func TestSeries(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = Series("", "", "", 0, "", start, end)
|
||||
if !errors.Is(err, errInvalidInput) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.ErrorIs(t, err, errInvalidInput)
|
||||
|
||||
_, err = Series(testExchanges[0].Name,
|
||||
"BTC", "MOON",
|
||||
864000, "spot",
|
||||
start, end)
|
||||
if err != nil && !errors.Is(err, errInvalidInput) && !errors.Is(err, ErrNoCandleDataFound) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = testhelpers.CloseDatabase(dbConn); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = Series(testExchanges[0].Name, "BTC", "MOON", 864000, "spot", start, end)
|
||||
require.ErrorIs(t, err, ErrNoCandleDataFound)
|
||||
assert.NoError(t, testhelpers.CloseDatabase(dbConn))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package datahistoryjob
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -258,9 +257,8 @@ func TestDataHistoryJob(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = db.SetRelationshipByNickname(results[2].Nickname, results[2].Nickname, 0)
|
||||
if !errors.Is(err, errCannotSetSamePrerequisite) {
|
||||
t.Errorf("received %v expected %v", err, errCannotSetSamePrerequisite)
|
||||
}
|
||||
assert.ErrorIs(t, err, errCannotSetSamePrerequisite)
|
||||
|
||||
err = db.SetRelationshipByNickname(results[3].Nickname, results[2].Nickname, 0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
@@ -159,11 +160,7 @@ func withdrawHelper(t *testing.T) {
|
||||
seedWithdrawData()
|
||||
|
||||
_, err := GetEventByUUID(withdraw.DryRunID.String())
|
||||
if err != nil {
|
||||
if !errors.Is(err, common.ErrNoResults) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
require.ErrorIs(t, err, common.ErrNoResults)
|
||||
|
||||
v, err := GetEventsByExchange(testExchanges[0].Name, 10)
|
||||
if err != nil {
|
||||
@@ -182,9 +179,7 @@ func withdrawHelper(t *testing.T) {
|
||||
if len(v) > 0 {
|
||||
_, err = GetEventByUUID(v[0].ID.String())
|
||||
if err != nil {
|
||||
if !errors.Is(err, common.ErrNoResults) {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.ErrorIs(t, err, common.ErrNoResults)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user