forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
routines_test.go
134 lines (125 loc) · 3.16 KB
/
routines_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package engine
import (
"errors"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
)
func TestWebsocketDataHandlerProcess(t *testing.T) {
ws := sharedtestvalues.NewTestWebsocket()
go WebsocketDataReceiver(ws)
ws.DataHandler <- "string"
time.Sleep(time.Second)
close(shutdowner)
}
func TestHandleData(t *testing.T) {
OrdersSetup(t)
var exchName = "exch"
var orderID = "testOrder.Detail"
err := WebsocketDataHandler(exchName, errors.New("error"))
if err == nil {
t.Error("Error not handled correctly")
}
err = WebsocketDataHandler(exchName, nil)
if err == nil {
t.Error("Expected nil data error")
}
err = WebsocketDataHandler(exchName, stream.TradeData{})
if err != nil {
t.Error(err)
}
err = WebsocketDataHandler(exchName, stream.FundingData{})
if err != nil {
t.Error(err)
}
err = WebsocketDataHandler(exchName, &ticker.Price{})
if err != nil {
t.Error(err)
}
err = WebsocketDataHandler(exchName, stream.KlineData{})
if err != nil {
t.Error(err)
}
origOrder := &order.Detail{
Exchange: fakePassExchange,
ID: orderID,
Amount: 1337,
Price: 1337,
}
err = WebsocketDataHandler(exchName, origOrder)
if err != nil {
t.Error(err)
}
// Send it again since it exists now
err = WebsocketDataHandler(exchName, &order.Detail{
Exchange: fakePassExchange,
ID: orderID,
Amount: 1338,
})
if err != nil {
t.Error(err)
}
if origOrder.Amount != 1338 {
t.Error("Bad pipeline")
}
err = WebsocketDataHandler(exchName, &order.Modify{
Exchange: fakePassExchange,
ID: orderID,
Status: order.Active,
})
if err != nil {
t.Error(err)
}
if origOrder.Status != order.Active {
t.Error("Expected order to be modified to Active")
}
err = WebsocketDataHandler(exchName, &order.Cancel{
Exchange: fakePassExchange,
ID: orderID,
})
if err != nil {
t.Error(err)
}
if origOrder.Status != order.Cancelled {
t.Error("Expected order status to be cancelled")
}
// Send some gibberish
err = WebsocketDataHandler(exchName, order.Stop)
if err != nil {
t.Error(err)
}
err = WebsocketDataHandler(exchName, stream.UnhandledMessageWarning{
Message: "there's an issue here's a tissue"},
)
if err != nil {
t.Error(err)
}
classificationError := order.ClassificationError{
Exchange: "test",
OrderID: "one",
Err: errors.New("lol"),
}
err = WebsocketDataHandler(exchName, classificationError)
if err == nil {
t.Error("Expected error")
}
if err.Error() != classificationError.Error() {
t.Errorf("Problem formatting error. Expected %v Received %v", classificationError.Error(), err.Error())
}
err = WebsocketDataHandler(exchName, &orderbook.Base{
ExchangeName: fakePassExchange,
Pair: currency.NewPair(currency.BTC, currency.USD),
})
if err != nil {
t.Error(err)
}
err = WebsocketDataHandler(exchName, "this is a test string")
if err != nil {
t.Error(err)
}
}