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

@@ -1,7 +1,6 @@
package binanceus
import (
"context"
"log"
"os"
reflects "reflect"
@@ -12,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
@@ -33,35 +31,25 @@ const (
)
var (
bi = &Binanceus{}
bi *Binanceus
testPairMapping = currency.NewBTCUSDT()
// this lock guards against orderbook tests race
binanceusOrderBookLock = &sync.Mutex{}
)
func TestMain(m *testing.M) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Binanceus load config error", err)
bi = new(Binanceus)
if err := testexch.Setup(bi); err != nil {
log.Fatalf("Binanceus Setup error: %s", err)
}
exchCfg, err := cfg.GetExchangeConfig("Binanceus")
if err != nil {
log.Fatal(err)
if apiKey != "" && apiSecret != "" {
bi.API.AuthenticatedSupport = true
bi.API.AuthenticatedWebsocketSupport = true
bi.SetCredentials(apiKey, apiSecret, "", "", "", "")
}
exchCfg.API.AuthenticatedSupport = true
exchCfg.API.AuthenticatedWebsocketSupport = true
exchCfg.API.Credentials.Key = apiKey
exchCfg.API.Credentials.Secret = apiSecret
bi.SetDefaults()
bi.Websocket = sharedtestvalues.NewTestWebsocket()
bi.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
err = bi.Setup(exchCfg)
if err != nil {
log.Fatal("Binanceus TestMain()", err)
}
bi.setupOrderbookManager(context.Background())
os.Exit(m.Run())
}