-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_test.go
More file actions
95 lines (67 loc) · 1.38 KB
/
fetch_test.go
File metadata and controls
95 lines (67 loc) · 1.38 KB
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
package fetch
import (
"context"
"fmt"
"io/ioutil"
"log/slog"
"os"
"path/filepath"
"testing"
_ "github.com/whosonfirst/go-reader-findingaid/v2"
"github.com/whosonfirst/go-reader/v2"
"github.com/whosonfirst/go-whosonfirst-uri"
"github.com/whosonfirst/go-writer/v3"
)
func TestFetch(t *testing.T) {
slog.SetLogLoggerLevel(slog.LevelDebug)
ctx := context.Background()
tmpdir, err := ioutil.TempDir("", "fetch")
if err != nil {
t.Fatal(err)
}
// fmt.Println("TMPDIR", tmpdir)
defer os.RemoveAll(tmpdir)
r, err := reader.NewReader(ctx, WHOSONFIRST_DATA_READER_URI)
if err != nil {
t.Fatal(err)
}
wr_uri := fmt.Sprintf("fs://%s", tmpdir)
wr, err := writer.NewWriter(ctx, wr_uri)
if err != nil {
t.Fatal(err)
}
fetcher_opts, err := DefaultOptions()
if err != nil {
t.Fatal(err)
}
fetcher, err := NewFetcher(ctx, r, wr, fetcher_opts)
if err != nil {
t.Fatal(err)
}
ids := []int64{1360695651}
belongs_to := []string{"all"}
_, err = fetcher.FetchIDs(ctx, ids, belongs_to...)
if err != nil {
t.Fatal(err)
}
to_verify := []int64{
1360695651,
101756499,
85633111,
1377694369,
102191581,
102063913,
85682553,
}
for _, id := range to_verify {
rel_path, err := uri.Id2RelPath(id)
if err != nil {
t.Fatal(err)
}
abs_path := filepath.Join(tmpdir, rel_path)
_, err = os.Stat(abs_path)
if err != nil {
t.Fatal(err)
}
}
}