-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgeoTiles_test.go
97 lines (72 loc) · 2.2 KB
/
geoTiles_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
91
92
93
94
95
96
97
package main
import (
"context"
"net/http"
"testing"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_proxyTiles(t *testing.T) {
app := &goBlog{
cfg: &config{},
}
hc := newFakeHttpClient()
hc.setHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello, World!"))
}))
app.httpClient = hc.Client
// Default tile source
m := chi.NewMux()
m.Get("/-/tiles/{s}/{z}/{x}/{y}.png", app.proxyTiles())
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://example.org/-/tiles/c/8/134/84.png", nil)
require.NoError(t, err)
resp, err := doHandlerRequest(req, m)
require.NoError(t, err)
_ = resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "https://c.tile.openstreetmap.org/8/134/84.png", hc.req.URL.String())
// Custom tile source
app.cfg.MapTiles = &configMapTiles{
Source: "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png",
}
m = chi.NewMux()
m.Get("/-/tiles/{s}/{z}/{x}/{y}.png", app.proxyTiles())
req, err = http.NewRequestWithContext(context.Background(), http.MethodGet, "https://example.org/-/tiles/c/8/134/84.png", nil)
require.NoError(t, err)
resp, err = doHandlerRequest(req, m)
require.NoError(t, err)
_ = resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "https://c.tile.opentopomap.org/8/134/84.png", hc.req.URL.String())
}
func Test_getMinZoom(t *testing.T) {
app := &goBlog{
cfg: &config{},
}
assert.Equal(t, 0, app.getMinZoom())
app.cfg.MapTiles = &configMapTiles{
MinZoom: 1,
}
assert.Equal(t, 1, app.getMinZoom())
}
func Test_getMaxZoom(t *testing.T) {
app := &goBlog{
cfg: &config{},
}
assert.Equal(t, 19, app.getMaxZoom())
app.cfg.MapTiles = &configMapTiles{
MaxZoom: 10,
}
assert.Equal(t, 10, app.getMaxZoom())
}
func Test_getMapAttribution(t *testing.T) {
app := &goBlog{
cfg: &config{},
}
assert.Equal(t, `© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors`, app.getMapAttribution())
app.cfg.MapTiles = &configMapTiles{
Attribution: "attribution",
}
assert.Equal(t, "attribution", app.getMapAttribution())
}