mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 07:26:47 +00:00
* Attempts to update orderbook so it doesn't need to sort * Reverts the ws ob stuff. Gets rid of sorting because it happens later. Adds some exchange features * update existing feature lists. Expands list definition to match my emotions * Adds bithumb bitmex and bitstamp. adds a couple more types * Features for you, features for me, features for bittrex, btcmarkets, btse, coinbasepro, coinut, exmo, gateio and gemini * Features for hitbtc, huobi, itbit, kraken, lakebtc, lbank, localbitcoins, okcoin, okex, poloniex, yobit, zb * Who can forget good old alphapoint? * Adds btcmarksets websocket :glitch_crab: fixes alphapoint features * Adds extra data not in the documentation :/ * Replaces websocket features by using protocol features. However, it breaks it due to import cycles. I'm not sure what I'll do just yet * Removes import cycle via duplicate structs. * Increases coverage of config with `TestCheckCurrencyConfigValues`. Moves all currency pair package types into their own files or places it at the bottom of files if necessary * Increase coverage in code.go * One way of determining a test has failed, is when to it fails. Removed redundant explanation * Increases code coverage of conversion * Lint fixes * Fixes orderbook tests * Re-adds sorting because its important to still have the internal pre-processed orderbook to be representative of a real orderbook * Secret lints that did not show up via Windows linting * Adds protocol package to contain exchange features * Fixes protocol implementation * Fixes ws tests * Addresses the following: Removes st-st-stutters in config types, changes GetAvailableForexProviders -> GetSupportedForexProviders, removes errors from tests where error is nil, removes orderbook setup when not necessary, removes import newlines, removes false bools from declaration, changes should of to should have * imports and casing * Fixes two more nil error checks
130 lines
2.5 KiB
Go
130 lines
2.5 KiB
Go
package base
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
b Base
|
|
)
|
|
|
|
func TestStart(t *testing.T) {
|
|
b = Base{
|
|
Name: "test",
|
|
Enabled: true,
|
|
Verbose: true,
|
|
Connected: true,
|
|
}
|
|
}
|
|
|
|
func TestIsEnabled(t *testing.T) {
|
|
if !b.IsEnabled() {
|
|
t.Error("base IsEnabled() error")
|
|
}
|
|
}
|
|
|
|
func TestIsConnected(t *testing.T) {
|
|
if !b.IsConnected() {
|
|
t.Error("base IsConnected() error")
|
|
}
|
|
}
|
|
|
|
func TestGetName(t *testing.T) {
|
|
if b.GetName() != "test" {
|
|
t.Error("base GetName() error")
|
|
}
|
|
}
|
|
|
|
type CommunicationProvider struct {
|
|
ICommunicate
|
|
|
|
isEnabled bool
|
|
isConnected bool
|
|
ConnectCalled bool
|
|
PushEventCalled bool
|
|
}
|
|
|
|
func (p *CommunicationProvider) IsEnabled() bool {
|
|
return p.isEnabled
|
|
}
|
|
|
|
func (p *CommunicationProvider) IsConnected() bool {
|
|
return p.isConnected
|
|
}
|
|
|
|
func (p *CommunicationProvider) Connect() error {
|
|
p.ConnectCalled = true
|
|
return nil
|
|
}
|
|
|
|
func (p *CommunicationProvider) PushEvent(e Event) error {
|
|
p.PushEventCalled = true
|
|
return nil
|
|
}
|
|
|
|
func (p *CommunicationProvider) GetName() string {
|
|
return "someTestProvider"
|
|
}
|
|
|
|
func TestSetup(t *testing.T) {
|
|
var ic IComm
|
|
testConfigs := []struct {
|
|
isEnabled bool
|
|
isConnected bool
|
|
shouldConnectCalled bool
|
|
provider ICommunicate
|
|
}{
|
|
{false, true, false, nil},
|
|
{false, false, false, nil},
|
|
{true, true, false, nil},
|
|
{true, false, true, nil},
|
|
}
|
|
for _, config := range testConfigs {
|
|
config.provider = &CommunicationProvider{
|
|
isEnabled: config.isEnabled,
|
|
isConnected: config.isConnected}
|
|
ic = append(ic, config.provider)
|
|
}
|
|
|
|
ic.Setup()
|
|
|
|
for idx, provider := range ic {
|
|
exp := testConfigs[idx].shouldConnectCalled
|
|
act := provider.(*CommunicationProvider).ConnectCalled
|
|
if exp != act {
|
|
t.Fatalf("provider should be enabled and not be connected: exp=%v, act=%v", exp, act)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPushEvent(t *testing.T) {
|
|
var ic IComm
|
|
testConfigs := []struct {
|
|
Enabled bool
|
|
Connected bool
|
|
PushEventCalled bool
|
|
provider ICommunicate
|
|
}{
|
|
{false, true, false, nil},
|
|
{false, false, false, nil},
|
|
{true, false, false, nil},
|
|
{true, true, true, nil},
|
|
}
|
|
for _, config := range testConfigs {
|
|
config.provider = &CommunicationProvider{
|
|
isEnabled: config.Enabled,
|
|
isConnected: config.Connected}
|
|
ic = append(ic, config.provider)
|
|
}
|
|
|
|
ic.PushEvent(Event{})
|
|
|
|
for idx, provider := range ic {
|
|
exp := testConfigs[idx].PushEventCalled
|
|
act := provider.(*CommunicationProvider).PushEventCalled
|
|
if exp != act {
|
|
t.Fatalf("provider should be enabled and connected: exp=%v, act=%v", exp, act)
|
|
}
|
|
}
|
|
}
|