forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_service_test.go
107 lines (88 loc) · 2.36 KB
/
server_service_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
package binance
import (
"fmt"
"net/http"
"testing"
"github.com/spectra-fund/go-binance/common"
"github.com/stretchr/testify/suite"
)
type serverServiceTestSuite struct {
baseTestSuite
}
func TestServerService(t *testing.T) {
suite.Run(t, new(serverServiceTestSuite))
}
func (s *serverServiceTestSuite) TestPing() {
data := []byte(`{}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
err := s.client.NewPingService().Do(newContext())
s.r().NoError(err)
}
func (s *serverServiceTestSuite) TestServerTime() {
data := []byte(`{
"serverTime": 1499827319559
}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
serverTime, err := s.client.NewServerTimeService().Do(newContext())
s.r().NoError(err)
s.r().EqualValues(1499827319559, serverTime)
}
func (s *serverServiceTestSuite) TestServerTimeError() {
s.mockDo([]byte("{}"), fmt.Errorf("dummy error"), http.StatusInternalServerError)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
_, err := s.client.NewServerTimeService().Do(newContext())
s.r().Error(err)
s.r().Contains(err.Error(), "dummy error")
}
func (s *serverServiceTestSuite) TestServerTimeBadRequest() {
s.mockDo([]byte(`{
"code": -1121,
"msg": "Invalid symbol."
}`), nil, http.StatusBadRequest)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
_, err := s.client.NewServerTimeService().Do(newContext())
s.r().Error(err)
s.r().True(common.IsAPIError(err))
}
func (s *serverServiceTestSuite) TestInvalidResponseBody() {
s.mockDo([]byte(``), nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
_, err := s.client.NewServerTimeService().Do(newContext())
s.r().Error(err)
s.r().False(common.IsAPIError(err))
}
func (s *serverServiceTestSuite) TestSetServerTime() {
data := []byte(`1399827319559`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
timeOffset, err := s.client.NewSetServerTimeService().Do(newContext())
s.r().NoError(err)
s.r().NotZero(s.client.TimeOffset)
s.r().EqualValues(timeOffset, s.client.TimeOffset)
}