Files
gocryptotrader/internal/testing/exchange/exchange_test.go
Adrian Gallagher ebcbfab358 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
2025-06-25 13:02:47 +10:00

38 lines
1.4 KiB
Go

package exchange
import (
"testing"
gws "github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/exchanges/binance"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
mockws "github.com/thrasher-corp/gocryptotrader/internal/testing/websocket"
)
// TestSetup exercises Setup
func TestSetup(t *testing.T) {
b := new(binance.Binance)
require.NoError(t, Setup(b), "Setup must not error")
assert.NotNil(t, b.Websocket, "Websocket should not be nil after Setup")
e := new(sharedtestvalues.CustomEx)
assert.ErrorIs(t, Setup(e), config.ErrExchangeNotFound, "Setup should error correctly on a missing exchange")
}
// TestMockHTTPInstance exercises MockHTTPInstance
func TestMockHTTPInstance(t *testing.T) {
b := new(binance.Binance)
require.NoError(t, Setup(b), "Test exchange Setup must not error")
require.NoError(t, MockHTTPInstance(b), "MockHTTPInstance with no optional path must not error")
require.NoError(t, MockHTTPInstance(b, "api"), "MockHTTPInstance with optional path must not error")
}
// TestMockWsInstance exercises MockWsInstance
func TestMockWsInstance(t *testing.T) {
b := MockWsInstance[binance.Binance](t, mockws.CurryWsMockUpgrader(t, func(_ testing.TB, _ []byte, _ *gws.Conn) error { return nil }))
require.NotNil(t, b, "MockWsInstance must not be nil")
}