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:
Adrian Gallagher
2025-06-25 13:02:47 +10:00
committed by GitHub
parent 61a3d765ee
commit ebcbfab358
38 changed files with 214 additions and 460 deletions

View File

@@ -12,7 +12,6 @@ import (
"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/core"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
@@ -28,7 +27,7 @@ import (
)
var (
h = &HitBTC{}
h *HitBTC
wsSetupRan bool
)
@@ -42,29 +41,19 @@ const (
var spotPair = currency.NewBTCUSD().Format(currency.PairFormat{Uppercase: true})
func TestMain(m *testing.M) {
h.SetDefaults()
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("HitBTC load config error", err)
}
hitbtcConfig, err := cfg.GetExchangeConfig("HitBTC")
if err != nil {
log.Fatal("HitBTC Setup() init error")
}
hitbtcConfig.API.AuthenticatedSupport = true
hitbtcConfig.API.AuthenticatedWebsocketSupport = true
hitbtcConfig.API.Credentials.Key = apiKey
hitbtcConfig.API.Credentials.Secret = apiSecret
h.Websocket = sharedtestvalues.NewTestWebsocket()
err = h.Setup(hitbtcConfig)
if err != nil {
log.Fatal("HitBTC setup error", err)
h = new(HitBTC)
if err := testexch.Setup(h); err != nil {
log.Fatalf("HitBTC Setup error: %s", err)
}
err = h.UpdateTradablePairs(context.Background(), false)
if err != nil {
log.Fatal("HitBTC setup error", err)
if apiKey != "" && apiSecret != "" {
h.API.AuthenticatedSupport = true
h.API.AuthenticatedWebsocketSupport = true
h.SetCredentials(apiKey, apiSecret, "", "", "", "")
}
if err := h.UpdateTradablePairs(context.Background(), false); err != nil {
log.Fatalf("HitBTC UpdateTradablePairs error: %s", err)
}
os.Exit(m.Run())