-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachereader_test.go
74 lines (52 loc) · 1.22 KB
/
cachereader_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 cachereader
import (
"context"
"fmt"
"github.com/whosonfirst/go-reader"
"io"
"io/ioutil"
"path/filepath"
"testing"
)
func TestCacheReader(t *testing.T) {
ctx := context.Background()
rel_path := "./fixtures"
abs_path, err := filepath.Abs(rel_path)
if err != nil {
t.Fatalf("Failed to derive absolute path, %v", err)
}
reader_uri := fmt.Sprintf("fs://%s", abs_path)
cache_uri := "gocache://"
cr_uri := fmt.Sprintf("cachereader://?reader=%s&cache=%s", reader_uri, cache_uri)
r, err := reader.NewReader(ctx, cr_uri)
if err != nil {
t.Fatalf("Failed to create new cachereader, %v", err)
}
to_test := []string{
"101736545.geojson",
}
for i := 0; i < 2; i++ {
for _, path := range to_test {
fh, err := r.Read(ctx, path)
if err != nil {
t.Fatalf("Failed to read %s, %v", path, err)
}
defer fh.Close()
_, err = io.Copy(ioutil.Discard, fh)
if err != nil {
t.Fatalf("Failed to copy %s, %v", path, err)
}
v, _ := GetLastRead(r, path)
switch i {
case 0:
if v != CacheMiss {
t.Fatalf("Expected cache miss on first read of %s", path)
}
default:
if v != CacheHit {
t.Fatalf("Expected cache hit after first read of %s", path)
}
}
}
}
}