-
Notifications
You must be signed in to change notification settings - Fork 49
/
relation_test.go
90 lines (75 loc) · 2.23 KB
/
relation_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package osmapi
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/paulmach/osm"
)
func TestRelation_urls(t *testing.T) {
ctx := context.Background()
url := ""
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
url = r.URL.String()
w.Write([]byte(`<osm></osm>`))
}))
defer ts.Close()
DefaultDatasource.BaseURL = ts.URL
defer func() {
DefaultDatasource.BaseURL = BaseURL
}()
t.Run("relation", func(t *testing.T) {
Relation(ctx, 1)
if !strings.Contains(url, "relation/1") {
t.Errorf("incorrect path: %v", url)
}
Relation(ctx, 1, At(time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC)))
if !strings.Contains(url, "relation/1?at=2016-01-01T00:00:00Z") {
t.Errorf("incorrect path: %v", url)
}
})
t.Run("relations", func(t *testing.T) {
Relations(ctx, []osm.RelationID{1, 2})
if !strings.Contains(url, "relations?relations=1,2") {
t.Errorf("incorrect path: %v", url)
}
Relations(ctx, []osm.RelationID{1, 2}, At(time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC)))
if !strings.Contains(url, "relations?relations=1,2&at=2016-01-01T00:00:00Z") {
t.Errorf("incorrect path: %v", url)
}
})
t.Run("relation version", func(t *testing.T) {
RelationVersion(ctx, 1, 2)
if !strings.Contains(url, "relation/1/2") {
t.Errorf("incorrect path: %v", url)
}
})
t.Run("relation history", func(t *testing.T) {
RelationHistory(ctx, 1)
if !strings.Contains(url, "relation/1/history") {
t.Errorf("incorrect path: %v", url)
}
})
t.Run("relation relations", func(t *testing.T) {
RelationRelations(ctx, 1)
if !strings.Contains(url, "relation/1/relations") {
t.Errorf("incorrect path: %v", url)
}
RelationRelations(ctx, 1, At(time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC)))
if !strings.Contains(url, "relation/1/relations?at=2016-01-01T00:00:00Z") {
t.Errorf("incorrect path: %v", url)
}
})
t.Run("relation full", func(t *testing.T) {
RelationFull(ctx, 1)
if !strings.Contains(url, "relation/1/full") {
t.Errorf("incorrect path: %v", url)
}
RelationFull(ctx, 1, At(time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC)))
if !strings.Contains(url, "relation/1/full?at=2016-01-01T00:00:00Z") {
t.Errorf("incorrect path: %v", url)
}
})
}