-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmarkets_status_test.go
83 lines (71 loc) · 2.77 KB
/
markets_status_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
package client
import (
"context"
"fmt"
"testing"
)
func TestMarketStatusRequestSetters(t *testing.T) {
msr := MarketStatus()
// Test Country setter
msr.Country("UK")
if msr.countryParams.Country != "UK" || msr.Error != nil {
t.Errorf("Country setter failed, got: %s, want: %s.", msr.countryParams.Country, "UK")
}
// Test invalid Country setter
msr.Country("UKK")
if msr.Error == nil {
t.Errorf("Country setter failed to catch invalid input.")
}
// Test Date setter
msr.Date("2022-01-01")
if msr.dateParams.Date != "2022-01-01" || msr.dateParams.From != "" || msr.dateParams.To != "" || msr.dateParams.Countback != nil {
t.Errorf("Date setter failed, got: %s, want: %s.", msr.dateParams.Date, "2022-01-01")
}
// Test From setter
msr.From("2022-01-01")
if msr.dateParams.From != "2022-01-01" || msr.dateParams.Date != "" || msr.dateParams.Countback != nil {
t.Errorf("From setter failed, got: %s, want: %s.", msr.dateParams.From, "2022-01-01")
}
// Test To setter
msr.To("2022-12-31")
if msr.dateParams.To != "2022-12-31" || msr.dateParams.Date != "" {
t.Errorf("To setter failed, got: %s, want: %s.", msr.dateParams.To, "2022-12-31")
}
// Test Countback setter
countback := 5
msr.Countback(countback)
if *msr.dateParams.Countback != countback || msr.dateParams.Date != "" || msr.dateParams.From != "" {
t.Errorf("Countback setter failed, got: %d, want: %d.", *msr.dateParams.Countback, countback)
}
}
func ExampleMarketStatus_packed() {
ctx := context.TODO()
msr, err := MarketStatus().From("2022-01-01").To("2022-01-10").Packed(ctx)
if err != nil {
fmt.Print(err)
return
}
fmt.Println(msr)
//Output: MarketStatusResponse{Date: [1641013200, 1641099600, 1641186000, 1641272400, 1641358800, 1641445200, 1641531600, 1641618000, 1641704400, 1641790800], Status: ["closed", "closed", "open", "open", "open", "open", "open", "closed", "closed", "open"]}
}
func ExampleMarketStatus_get() {
ctx := context.TODO()
msr, err := MarketStatus().From("2022-01-01").To("2022-01-10").Get(ctx)
if err != nil {
fmt.Print(err)
return
}
for _, report := range msr {
fmt.Println(report)
}
// Output: MarketStatusReport{Date: 2022-01-01, Open: false, Closed: true}
// MarketStatusReport{Date: 2022-01-02, Open: false, Closed: true}
// MarketStatusReport{Date: 2022-01-03, Open: true, Closed: false}
// MarketStatusReport{Date: 2022-01-04, Open: true, Closed: false}
// MarketStatusReport{Date: 2022-01-05, Open: true, Closed: false}
// MarketStatusReport{Date: 2022-01-06, Open: true, Closed: false}
// MarketStatusReport{Date: 2022-01-07, Open: true, Closed: false}
// MarketStatusReport{Date: 2022-01-08, Open: false, Closed: true}
// MarketStatusReport{Date: 2022-01-09, Open: false, Closed: true}
// MarketStatusReport{Date: 2022-01-10, Open: true, Closed: false}
}