exchange

package
v0.0.0-...-ca9efe7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurryWsMockUpgrader

func CurryWsMockUpgrader(tb testing.TB, wsHandler WsMockFunc) http.HandlerFunc

CurryWsMockUpgrader curries a WsMockUpgrader with a testing.TB and a mock func bridging the gap between information known before the Server is created and during a request

func FixtureToDataHandler

func FixtureToDataHandler(tb testing.TB, fixturePath string, reader func([]byte) error)

FixtureToDataHandler squirts the contents of a file to a reader function (probably e.wsHandleData)

func MockHTTPInstance

func MockHTTPInstance(e exchange.IBotExchange) error

MockHTTPInstance takes an existing Exchange instance and attaches it to a new http server It is expected to be run once, since http requests do not often tangle with each other

func MockWsInstance

func MockWsInstance[T any, PT interface {
	*T
	exchange.IBotExchange
}](tb testing.TB, h http.HandlerFunc) *T

MockWsInstance creates a new Exchange instance with a mock websocket instance and HTTP server It accepts an exchange package type argument and a http.HandlerFunc See CurryWsMockUpgrader for a convenient way to curry t and a ws mock function It is expected to be run from any WS tests which need a specific response function No default subscriptions will be run since they disrupt unit tests

func Setup

func Setup(e exchange.IBotExchange) error

Setup takes an empty exchange instance and loads config for it from testdata/configtest and connects a NewTestWebsocket

func SetupWs

func SetupWs(tb testing.TB, e exchange.IBotExchange)

SetupWs is a helper function to connect both auth and normal websockets It will skip the test if websockets are not enabled It's up to the test to skip if it requires creds, though

func UpdatePairsOnce

func UpdatePairsOnce(tb testing.TB, e exchange.IBotExchange)

UpdatePairsOnce ensures pairs are only updated once in parallel tests A clone of the cache of the updated pairs is used to populate duplicate requests

func WsMockUpgrader

func WsMockUpgrader(tb testing.TB, w http.ResponseWriter, r *http.Request, wsHandler WsMockFunc)

WsMockUpgrader handles upgrading an initial HTTP request to WS, and then runs a for loop calling the mock func on each input

Types

type WsMockFunc

type WsMockFunc func([]byte, *websocket.Conn) error

WsMockFunc is a websocket handler to be called with each websocket message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL