-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebsocket_test.go
More file actions
39 lines (32 loc) · 870 Bytes
/
websocket_test.go
File metadata and controls
39 lines (32 loc) · 870 Bytes
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
package binancestream
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func init() {
EnableDebugLogger()
}
func Test_SubscribeRequest(t *testing.T) {
var ctx context.Context
var cancel context.CancelFunc
var err error
m := newBinanceWs()
err = m.connect()
assert.Nil(t, err)
go m.readPump()
defer m.close()
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
r, err := m.request(ctx, "SUBSCRIBE", "btcusdt@kline_1m")
assert.NoError(t, err)
assert.NotNil(t, r)
assert.EqualValues(t, r.Result, []byte("null"))
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
r, err = m.request(ctx, "SUBSCRIBEX", "btcusdtsss@kline_1m")
assert.Error(t, err)
assert.Contains(t, err.Error(), "Invalid request: unknown variant `SUBSCRIBEX`")
assert.Nil(t, r)
}