-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyahoofin_test.go
58 lines (45 loc) · 1.08 KB
/
yahoofin_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
package yahoofin
import (
"encoding/csv"
"strings"
"testing"
"time"
)
func TestClient(t *testing.T) {
client, err := NewClient()
if err != nil {
t.Error(err)
}
ticker := "AAPL"
startDate := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2016, time.February, 1, 0, 0, 0, 0, time.UTC)
fields := []Field{History, Dividend}
for _, field := range fields {
csvString, err := client.GetSecurityDataString(ticker, startDate, endDate, field)
if err != nil {
t.Error(err)
}
rdr := strings.NewReader(csvString)
csvRdr := csv.NewReader(rdr)
records, err := csvRdr.ReadAll()
if err != nil {
t.Error(err)
}
if len(records) == 0 {
t.Error("No records parsed")
}
prices, err := client.GetSecurityData(ticker, startDate, endDate, History)
if err != nil {
t.Error(err)
}
if len(prices) == 0 {
t.Error("No records parsed")
}
}
// Test bad ticker
invalidTicker := "NotAT1cker"
_, err = client.GetSecurityData(invalidTicker, startDate, endDate, History)
if err == nil {
t.Error("No error for invalid ticker")
}
}