-
Notifications
You must be signed in to change notification settings - Fork 0
/
retriever_test.go.bak
52 lines (50 loc) · 1.31 KB
/
retriever_test.go.bak
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
package yfgo_lib
import (
"testing"
// "strconv"
"os"
"encoding/json"
)
func TestRetrieveJSON(t *testing.T) {
timeAgo := 60 * 24 * 7
then, now := UnixTimeAgoAndNow(timeAgo)
params := []QueryParam{
{Name: "interval", Value: "1m"},
{Name: "period1", Value: strconv.FormatInt(then, 10)},
{Name: "period2", Value: strconv.FormatInt(now, 10)},
}
baseURL := "https://query2.finance.yahoo.com/v8/finance/chart"
url := MakeURL(baseURL, "COIN", params)
body, err := RetrieveJSON(url)
if err != nil {
t.Errorf("Retrieving JSON file failed")
}
err = SaveJSON(body)
if err != nil {
t.Errorf("JSON file cannot be saved")
}
body, err := os.ReadFile("output.json")
if err != nil {
t.Errorf("JSON file cannot be read")
return
}
content, err := ParseJSON(body)
if err != nil {
t.Errorf("JSON cannot be parsed")
return
}
_, err = json.Marshal(content)
if err != nil {
t.Errorf("JSON cannot be restored")
return
}
history, err := GenerateHistoryFromParsedJSON(body)
if err != nil {
t.Errorf("History cannot be generated")
return
}
if len(history.Open) == 0 {
t.Errorf("Open does not have any data Value")
return
}
}