-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_test.go
73 lines (51 loc) · 1.29 KB
/
git_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
package git
import (
"context"
"encoding/json"
"github.com/sfomuseum/go-lookup/catalog"
"github.com/sfomuseum/go-lookup/iterator"
"io"
"testing"
)
type properties struct {
Id int64 `json:"wof:id"`
Name string `json:"wof:name"`
}
type feature struct {
Properties properties `json:"properties"`
}
func AppendFunc(ctx context.Context, c catalog.Catalog, fh io.ReadCloser) error {
var f *feature
dec := json.NewDecoder(fh)
err := dec.Decode(&f)
if err != nil {
return err
}
props := f.Properties
c.LoadOrStore(props.Name, props.Id)
return nil
}
func TestGitLookerUpper(t *testing.T) {
ctx := context.Background()
lu, err := iterator.NewIterator(ctx, "https://github.com/sfomuseum-data/sfomuseum-data-maps.git")
if err != nil {
t.Fatalf("Failed to create new GitLookerUpper, %v", err)
}
c, err := catalog.NewSyncMapCatalog(ctx, "syncmap://")
if err != nil {
t.Fatalf("Failed to create new SyncMapCatalog, %v", err)
}
err = lu.Append(ctx, c, AppendFunc)
if err != nil {
t.Fatalf("Failed to append lookup to catalog, %v", err)
}
key := "SFO (2014)"
expected := int64(1477881751)
v, ok := c.Load(key)
if !ok {
t.Fatalf("Failed to locate key '%s'", key)
}
if v.(int64) != expected {
t.Fatalf("Unexpected value. Wanted '%d' but got '%d'", expected, v.(int64))
}
}