-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregate_request_options_test.go
75 lines (63 loc) · 2.34 KB
/
aggregate_request_options_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
package moexiss
import (
"testing"
"time"
)
func TestAggregateReqOptionsBuilder_Build(t *testing.T) {
expectStruct := AggregateRequestOptions{}
bld := NewAggregateReqOptionsBuilder()
if got, expected := *bld.Build(), expectStruct; got != expected {
t.Fatalf("Error: expecting `%v` AggregateRequestOptions \ngot `%v` AggregateRequestOptions \ninstead", expected, got)
}
}
func TestAggregateReqOptionsBuilder_Lang(t *testing.T) {
expectStruct := AggregateRequestOptions{lang: LangEn}
bld := NewAggregateReqOptionsBuilder()
bld.Lang(LangEn)
if got, expected := *bld.Build(), expectStruct; got != expected {
t.Fatalf("Error: expecting `%v` \ngot `%v` \ninstead", expected, got)
}
}
func TestAggregateReqOptionsBuilder_Date(t *testing.T) {
date := time.Now()
expectStruct := AggregateRequestOptions{date: date}
bld := NewAggregateReqOptionsBuilder()
bld.Date(date)
if got, expected := *bld.Build(), expectStruct; got != expected {
t.Fatalf("Error: expecting `%v` \ngot `%v` \ninstead", expected, got)
}
}
func TestNewAggregateReqOptionsBuilder(t *testing.T) {
date := time.Now()
expectStruct := AggregateRequestOptions{
lang: LangRu,
date: date}
bld := NewAggregateReqOptionsBuilder()
bld.Date(date).Lang(LangRu)
if got, expected := *bld.Build(), expectStruct; got != expected {
t.Fatalf("Error: expecting `%v` \ngot `%v` \ninstead", expected, got)
}
}
func TestAddAggregateRequestOptionsNilOptions(t *testing.T) {
var income *AggregateRequestOptions = nil
c := NewClient(nil)
url, _ := c.BaseURL.Parse("aggregates.json")
gotURL := addAggregateRequestOptions(url, income)
expected := `https://iss.moex.com/iss/aggregates.json?iss.json=extended&iss.meta=off`
if got := gotURL.String(); got != expected {
t.Fatalf("Error: expecting url :\n`%s` \ngot \n`%s` \ninstead", expected, got)
}
}
func TestAddAggregateRequestOptions(t *testing.T) {
var incomeOptions = NewAggregateReqOptionsBuilder().
Lang(LangEn).
Date(time.Date(2021, 2, 24, 12, 0, 0, 0, time.UTC)).
Build()
c := NewClient(nil)
url, _ := c.BaseURL.Parse("aggregates.json")
gotURL := addAggregateRequestOptions(url, incomeOptions)
expected := `https://iss.moex.com/iss/aggregates.json?date=2021-02-24&iss.json=extended&iss.meta=off&lang=en`
if got := gotURL.String(); got != expected {
t.Fatalf("Error: expecting url :\n`%s` \ngot \n`%s` \ninstead", expected, got)
}
}