-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgarantex_test.go
154 lines (148 loc) · 2.93 KB
/
garantex_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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package marketdata
import (
"net/url"
"reflect"
"testing"
)
func Test_Garantex_GetDOM(t *testing.T) {
got, err := Garantex().GetDOM("usdtrub")
if err != nil {
t.Errorf("error getting data = %v", err)
return
}
if reflect.ValueOf(got).IsZero() {
t.Error("returned empty data")
}
}
func TestGarantexHistoryConfig_toParams(t *testing.T) {
type fields struct {
Market string
Limit int
From int
To int
Order string
}
tests := []struct {
name string
fields fields
want url.Values
}{
{
name: "market",
fields: fields{
Market: "usdtbtc",
},
want: url.Values{
"market": []string{"usdtbtc"},
},
},
{
name: "market+limit",
fields: fields{
Market: "usdtbtc",
Limit: 1000,
},
want: url.Values{
"market": []string{"usdtbtc"},
"limit": []string{"1000"},
},
},
{
name: "market+limit+from",
fields: fields{
Market: "usdtbtc",
Limit: 1000,
From: 343434,
},
want: url.Values{
"market": []string{"usdtbtc"},
"limit": []string{"1000"},
"from": []string{"343434"},
},
},
{
name: "market+limit+from+to",
fields: fields{
Market: "usdtbtc",
Limit: 1000,
From: 343434,
To: 434343,
},
want: url.Values{
"market": []string{"usdtbtc"},
"limit": []string{"1000"},
"from": []string{"343434"},
"to": []string{"434343"},
},
},
{
name: "market+limit+from+to+order",
fields: fields{
Market: "usdtbtc",
Limit: 1000,
From: 343434,
To: 434343,
Order: "DESC",
},
want: url.Values{
"market": []string{"usdtbtc"},
"limit": []string{"1000"},
"from": []string{"343434"},
"to": []string{"434343"},
"order_by": []string{"DESC"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := GarantexHistoryConfig{
Market: tt.fields.Market,
Limit: tt.fields.Limit,
From: tt.fields.From,
To: tt.fields.To,
Order: tt.fields.Order,
}
if got := c.toParams(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GarantexHistoryConfig.toParams() = %v, want %v", got, tt.want)
}
})
}
}
func Test_garantex_GetHistory(t *testing.T) {
tests := []struct {
name string
config GarantexHistoryConfig
wantErr bool
}{
{
name: "default",
config: GarantexHistoryConfig{
Market: "usdtrub",
Limit: 1000,
},
wantErr: false,
},
{
name: "badmarket",
config: GarantexHistoryConfig{
Market: "badmarket",
Limit: 1000,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Garantex().GetHistory(tt.config)
if err != nil {
if !tt.wantErr {
t.Errorf("garantex.GetHistory() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
if len(got) < tt.config.Limit {
t.Errorf("garantex.GetHistory() returned %d records, limit = %d", len(got), tt.config.Limit)
}
})
}
}