forked from kellydunn/golang-geo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencage_geocoder_test.go
74 lines (63 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package geo
import (
"fmt"
"testing"
)
func TestSetOpencageAPIKey(t *testing.T) {
SetOpenCageAPIKey("foo")
if OpenCageAPIKey != "foo" {
t.Errorf("Mismatched value for OpencageAPIKey. Expected: 'foo', Actual: %s", OpenCageAPIKey)
}
}
func TestSetOpenCageGeocodeURL(t *testing.T) {
SetOpenCageGeocodeURL("foo")
if opencageGeocodeURL != "foo" {
t.Errorf("Mismatched value for googleGeocoeURL. Expected: 'foo', Actual: %s", opencageGeocodeURL)
}
}
func TestOpencageGeocoderQueryStr(t *testing.T) {
// Empty API Key
SetOpenCageAPIKey("")
address := "123 fake st"
res, err := opencageGeocodeQueryStr(address)
if err != nil {
t.Errorf("Error creating query string: %v", err)
}
expected := "?q=123+fake+st&pretty=1"
if res != expected {
t.Errorf(fmt.Sprintf("Mismatched query string. Expected: %s. Actual: %s", expected, res))
}
// Set api key to some value
SetOpenCageAPIKey("foo")
res, err = opencageGeocodeQueryStr(address)
if err != nil {
t.Errorf("Error creating query string: %v", err)
}
expected = "?q=123+fake+st&key=foo&pretty=1"
if res != expected {
t.Errorf(fmt.Sprintf("Mismatched query string. Expected: %s. Actual: %s", expected, res))
}
}
func TestOpencageReverseGeocoderQueryStr(t *testing.T) {
// Empty API Key
SetOpenCageAPIKey("")
p := &Point{lat: 123.45, lng: 56.78}
res, err := opencageReverseGeocodeQueryStr(p)
if err != nil {
t.Errorf("Error creating query string: %v", err)
}
expected := "?q=123.450000,56.780000&pretty=1"
if res != expected {
t.Errorf(fmt.Sprintf("Mismatched query string. Expected: %s. Actual: %s", expected, res))
}
// Set api key to some value
SetOpenCageAPIKey("foo")
res, err = opencageReverseGeocodeQueryStr(p)
if err != nil {
t.Errorf("Error creating query string: %v", err)
}
expected = "?q=123.450000,56.780000&key=foo&pretty=1"
if res != expected {
t.Errorf(fmt.Sprintf("Mismatched query string. Expected: %s. Actual: %s", expected, res))
}
}