-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_test.go
57 lines (42 loc) · 1.26 KB
/
sql_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
package sqlite
import (
"context"
"io"
"path/filepath"
"sync/atomic"
"testing"
_ "github.com/mattn/go-sqlite3"
"github.com/whosonfirst/go-whosonfirst-iterate/v2/iterator"
)
func TestSQLiteEmitter(t *testing.T) {
ctx := context.Background()
rel_path := "fixtures/sfomuseum-maps.db"
abs_path, err := filepath.Abs(rel_path)
if err != nil {
t.Fatalf("Failed to derive absolute path for '%s', %v", rel_path, err)
}
uris := map[string]int32{
"sql://sqlite3": int32(37),
"sql://sqlite3?processes=10": int32(37),
"sql://sqlite3?include=properties.sfomuseum:uri=2019": int32(1),
"sql://sqlite3?exclude=properties.sfomuseum:uri=2019": int32(36),
}
for iter_uri, expected_count := range uris {
count := int32(0)
iter_cb := func(ctx context.Context, path string, r io.ReadSeeker, args ...interface{}) error {
atomic.AddInt32(&count, 1)
return nil
}
iter, err := iterator.NewIterator(ctx, iter_uri, iter_cb)
if err != nil {
t.Fatalf("Failed to create new iterator, %v", err)
}
err = iter.IterateURIs(ctx, abs_path)
if err != nil {
t.Fatalf("Failed to iterate %s, %v", abs_path, err)
}
if count != expected_count {
t.Fatalf("Unexpected count for '%s': %d (expected: %d)", iter_uri, count, expected_count)
}
}
}