mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +00:00
exchanges: Improve TestMain usage (#1946)
* exchanges: Improve TestMain usage * exchanges: Further cleanups * exchanges/kucoin: update TestProcessOrderbook to use test context * refactor: rename SetRunning to SetRunningURL for clarity across exchanges
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||
@@ -36,29 +35,20 @@ const (
|
||||
canManipulateRealOrders = false
|
||||
)
|
||||
|
||||
var b = &Bitmex{}
|
||||
var b *Bitmex
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
b.SetDefaults()
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
||||
if err != nil {
|
||||
log.Fatal("Bitmex load config error", err)
|
||||
}
|
||||
bitmexConfig, err := cfg.GetExchangeConfig("Bitmex")
|
||||
if err != nil {
|
||||
log.Fatal("Bitmex Setup() init error")
|
||||
b = new(Bitmex)
|
||||
if err := testexch.Setup(b); err != nil {
|
||||
log.Fatalf("Bitmex Setup error: %s", err)
|
||||
}
|
||||
|
||||
bitmexConfig.API.AuthenticatedSupport = true
|
||||
bitmexConfig.API.AuthenticatedWebsocketSupport = true
|
||||
bitmexConfig.API.Credentials.Key = apiKey
|
||||
bitmexConfig.API.Credentials.Secret = apiSecret
|
||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
||||
err = b.Setup(bitmexConfig)
|
||||
if err != nil {
|
||||
log.Fatal("Bitmex setup error", err)
|
||||
if apiKey != "" && apiSecret != "" {
|
||||
b.API.AuthenticatedSupport = true
|
||||
b.API.AuthenticatedWebsocketSupport = true
|
||||
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -486,7 +476,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
||||
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +493,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
||||
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,7 +522,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, order.New, response.Status)
|
||||
} else {
|
||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
||||
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,7 +542,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
||||
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,7 +563,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, resp.Status, "CancelAllOrders must not fail to cancel orders")
|
||||
} else {
|
||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
||||
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user