-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommodities_test.go
134 lines (118 loc) · 3.13 KB
/
commodities_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
package goiex
import (
"log"
"net/http"
"strconv"
"testing"
"github.com/dnaeon/go-vcr/recorder"
)
func TestNewCommodities(t *testing.T) {
cm := NewCommodities("test_token", "stable", sandboxURL, nil)
expected = "data-points/"
actual = cm.APIURL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = true
actual = cm.Client() == nil
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "test_token"
actual = cm.Token()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "https://sandbox.iexapis.com/"
actual = cm.URL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "stable"
actual = cm.Version()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}
func TestCommoditiesPrices(t *testing.T) {
rec, err := recorder.New("cassettes/data_point/commodities_prices")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewCommodities(testToken, DefaultVersion, sandboxURL, httpClient)
// Oil Prices
prices, err := cli.CommoditiesPrices("DCOILWTICO")
if err != nil {
t.Error(err)
}
expected = 53.93
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
// Natural Gas Prices
prices, err = cli.CommoditiesPrices("DHHNGSP")
if err != nil {
t.Error(err)
}
expected = 2.22
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
// Heating Oil Prices
prices, err = cli.CommoditiesPrices("DHOILNYH")
if err != nil {
t.Error(err)
}
expected = 1.98
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
// Jet Fuel Prices
prices, err = cli.CommoditiesPrices("DJFUELUSGULF")
if err != nil {
t.Error(err)
}
expected = 1.942
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
// Diesel Prices
prices, err = cli.CommoditiesPrices("GASDESW")
if err != nil {
t.Error(err)
}
expected = 3.14
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
// Gas Prices
prices, err = cli.CommoditiesPrices("GASREGCOVW")
if err != nil {
t.Error(err)
}
expected = 2.541
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
// Propane Prices
prices, err = cli.CommoditiesPrices("DPROPANEMBTX")
if err != nil {
t.Error(err)
}
expected = 0.482
actual, _ = strconv.ParseFloat(string(prices.([]uint8)), 64)
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}