-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobist_test.go
74 lines (60 loc) · 1.15 KB
/
gobist_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
package gobist
import (
"reflect"
"testing"
"time"
)
var (
symbols = []string{"TUPRS", "BIMAS", "KCHOL"}
)
func TestCrumb(t *testing.T) {
crumbStr, err := setYahooCrumb()
if err != nil {
t.Fatal(err)
}
if crumbStr == "Too Many Requests" {
t.Fatalf(crumbStr)
} else {
t.Logf("crumb: %s", crumbStr)
}
}
func TestBist_GetQuote(t *testing.T) {
bist := New()
q, err := bist.GetQuote(symbols)
assertError(t, err)
assertNotNil(t, q)
if q != nil {
t.Logf(q.ToJson())
}
}
func TestBist_GetQuoteWithHistory(t *testing.T) {
bist := New()
d, _ := time.Parse(time.DateOnly, "2024-10-03")
q, err := bist.GetQuoteWithHistory(symbols, d)
assertError(t, err)
assertNotNil(t, q)
if q != nil {
t.Logf(q.ToJson())
}
}
func assertError(t *testing.T, err error) {
if err != nil {
t.Errorf("Error occurred [%v]", err)
}
}
func assertNotNil(t *testing.T, v interface{}) {
if isNil(v) {
t.Errorf("[%v] was expected to be non-nil", v)
}
}
func isNil(v interface{}) bool {
if v == nil {
return true
}
rv := reflect.ValueOf(v)
kind := rv.Kind()
if kind >= reflect.Chan && kind <= reflect.Slice && rv.IsNil() {
return true
}
return false
}