-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test.go
More file actions
60 lines (42 loc) · 1.13 KB
/
api_test.go
File metadata and controls
60 lines (42 loc) · 1.13 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
package reader
import (
"context"
"flag"
"fmt"
"io"
"io/ioutil"
"testing"
"github.com/whosonfirst/go-reader/v2"
)
var access_token = flag.String("access-token", "", "A valid GitHub Oauth2 access token")
func TestAPIReader(t *testing.T) {
if *access_token == "" {
return
}
owner := "whosonfirst-data"
repo := "whosonfirst-data-admin-ca"
branch := "master" // pending rollover (20210114/thisisaaronland)
reader_uri := fmt.Sprintf("githubapi://%s/%s?branch=%s&access_token=%s", owner, repo, branch, *access_token)
file_uri := "data/101/736/545/101736545.geojson"
ctx := context.Background()
r, err := reader.NewReader(ctx, reader_uri)
if err != nil {
t.Fatalf("Failed to create new reader, %v", err)
}
fh, err := r.Read(ctx, file_uri)
if err != nil {
t.Fatalf("Failed to read %s, %v", file_uri, err)
}
defer fh.Close()
_, err = io.Copy(ioutil.Discard, fh)
if err != nil {
t.Fatalf("Failed to copy %s, %v", file_uri, err)
}
exists, err := r.Exists(ctx, file_uri)
if err != nil {
t.Fatalf("Failed to determine if %s exists, %v", file_uri, err)
}
if !exists {
t.Fatalf("Expected %s to exist", file_uri)
}
}