-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata_apis_test.go
79 lines (69 loc) · 1.77 KB
/
data_apis_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
package goiex
import (
"log"
"net/http"
"net/url"
"testing"
"github.com/dnaeon/go-vcr/recorder"
)
func TestNewDataAPI(t *testing.T) {
u, _ := url.Parse(SandboxBaseURL)
da := NewDataAPI("test_token", "", u, nil)
expected = "https://sandbox.iexapis.com/"
actual = da.URL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = ""
actual = da.APIURL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "test_token"
actual = da.Token()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}
func TestDataPoints(t *testing.T) {
rec, err := recorder.New("cassettes/data_api/data_points")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
u, _ := url.Parse(SandboxBaseURL)
cli := NewDataAPI(testToken, DefaultVersion, u, httpClient)
datapoints, err := cli.DataPoints("aapl")
if err != nil {
t.Error(err)
}
if len(datapoints) == 0 {
t.Errorf("\nExpected datapoints to be not empty\n")
}
}
func TestDataPoint(t *testing.T) {
rec, err := recorder.New("cassettes/data_api/data_points_aapl_accountspayable")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
u, _ := url.Parse(SandboxBaseURL)
cli := NewDataAPI(testToken, DefaultVersion, u, httpClient)
datapoint, err := cli.DataPoint("aapl", "ACCOUNTSPAYABLE")
if err != nil {
t.Error(err)
}
expected = 37661668256.0
actual = datapoint.(float64)
if expected != actual {
t.Errorf("\nExpected: %f\nActual: %f\n", expected, actual)
}
}