-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathav_test.go
47 lines (40 loc) · 1.1 KB
/
av_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
package av
import (
"net/http"
"testing"
)
func TestNewClient(t *testing.T) {
if NewClient(testApiKey) == nil {
t.Error("got nil client")
}
}
func TestClient_StockTimeSeries_buildsUrl(t *testing.T) {
const (
expected = "query?apikey=test&datatype=csv&function=TIME_SERIES_DAILY&outputsize=compact&symbol=TEST"
)
res := &http.Response{
Body: NewBuffCloser(sampleTimeSeriesData),
StatusCode: http.StatusOK,
}
conn := NewResponseConnection(res)
client := NewClientConnection(testApiKey, conn)
client.StockTimeSeries(TimeSeriesDaily, "TEST")
if conn.endpoint.String() != expected {
t.Errorf("unexpected url, want %s got %s", expected, conn.endpoint.String())
}
}
func TestClient_StockTimeSeries_getsResults(t *testing.T) {
res := &http.Response{
Body: NewBuffCloser(sampleTimeSeriesData),
StatusCode: http.StatusOK,
}
conn := NewResponseConnection(res)
client := NewClientConnection(testApiKey, conn)
result, err := client.StockTimeSeries(TimeSeriesDaily, "TEST")
if err != nil {
t.Fatalf("unexpected error, got %v", err)
}
if result == nil {
t.Error("nil results")
}
}