forked from kellydunn/golang-geo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencage_geocoder_test.go
56 lines (43 loc) · 1.41 KB
/
opencage_geocoder_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
package geo
import (
"fmt"
"testing"
)
// Test extracting LatLng from OpenCage Geocoding Response
func TestOpenCageExtractLatLngFromRequest(t *testing.T) {
g := &OpenCageGeocoder{}
data, err := GetMockResponse("test/data/opencage_geocode_success.json")
if err != nil {
t.Error("%v\n", err)
}
lat, lng, err := g.extractLatLngFromResponse(data)
if err != nil {
t.Error("%v\n", err)
}
if lat != -23.5373732 && lng != -46.8374628 {
t.Error(fmt.Sprintf("Expected: [-23.5373732, -46.8374628], Got: [%f, %f]", lat, lng))
}
}
func TestOpenCageExtractAddressFromRequest(t *testing.T) {
g := &OpenCageGeocoder{}
data, err := GetMockResponse("test/data/opencage_geocode_success.json")
if err != nil {
t.Error("%v\n", err)
}
address := g.extractAddressFromResponse(data)
if address != "Rua Cafelândia, Carapicuíba - SP, Brazil" {
t.Error(fmt.Sprintf("Expected: Rua Cafelândia, Carapicuíba - SP, Brazil, Got: [%s]", address))
}
}
// Test extracting LatLng from OpenCage Geocoding Response when no results are returned
func TestOpenCageExtractLatLngFromRequestZeroResults(t *testing.T) {
g := &OpenCageGeocoder{}
data, err := GetMockResponse("test/data/opencage_geocode_zero_results.json")
if err != nil {
t.Error("%v\n", err)
}
_, _, err = g.extractLatLngFromResponse(data)
if err != opencageZeroResultsError {
t.Error(fmt.Sprintf("Expected error: %v, Got: %v"), opencageZeroResultsError, err)
}
}