forked from olivere/mapquest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static_map_api_test.go
77 lines (71 loc) · 1.39 KB
/
static_map_api_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
package mapquest
import (
_ "bytes"
_ "image/png"
_ "io/ioutil"
"testing"
)
func TestStaticMapBuildURLs(t *testing.T) {
testKey, err := readKey(t)
if err != nil {
t.Fail()
return
}
tests := []struct {
Request *StaticMapRequest
URL string
}{
{
Request: &StaticMapRequest{
Center: &GeoPoint{
Longitude: 11.54165,
Latitude: 48.151313,
},
Zoom: 9,
Width: 500,
Height: 300,
Format: "png",
},
URL: "http://open.mapquestapi.com/staticmap/v4/getmap?center=48.151313,11.541650&size=500,300&zoom=9&imagetype=png&key=" + testKey,
},
}
client := NewClient(testKey)
for _, test := range tests {
got, err := client.StaticMap().buildURL(test.Request)
if err != nil {
t.Fatalf("expeced no error, got: %v", err)
}
if got != test.URL {
t.Errorf("expected %q, got: %q", test.URL, got)
}
}
}
func TestStaticMapGet(t *testing.T) {
key, err := readKey(t)
if err != nil {
t.Fail()
return
}
client := NewClient(key)
req := &StaticMapRequest{
Center: &GeoPoint{
Longitude: 11.54165,
Latitude: 48.151313,
},
Zoom: 9,
Width: 500,
Height: 300,
Format: "png",
}
img, err := client.StaticMap().Get(req)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if img == nil {
t.Fatalf("expected image data, got: %v", img)
}
bounds := img.Bounds()
if bounds.Empty() {
t.Fatal("expected a non-empty image")
}
}