2019-12-19 17:17:13 +01:00
|
|
|
package osm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFindLocation(t *testing.T) {
|
2019-12-20 11:30:58 +01:00
|
|
|
t.Run("BerlinFernsehturm", func(t *testing.T) {
|
2019-12-19 17:17:13 +01:00
|
|
|
lat := 52.5208
|
2019-12-20 11:30:58 +01:00
|
|
|
lng := 13.40953
|
2019-12-19 17:17:13 +01:00
|
|
|
|
2019-12-20 11:30:58 +01:00
|
|
|
l, err := FindLocation(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.False(t, l.Cached)
|
|
|
|
assert.Equal(t, 189675302, l.PlaceID)
|
2019-12-20 23:05:44 +01:00
|
|
|
assert.Equal(t, "Fernsehturm Berlin", l.LocTitle)
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.Equal(t, "10178", l.Address.Postcode)
|
|
|
|
assert.Equal(t, "Berlin", l.Address.State)
|
|
|
|
assert.Equal(t, "de", l.Address.CountryCode)
|
|
|
|
assert.Equal(t, "Germany", l.Address.Country)
|
|
|
|
|
|
|
|
l.PlaceID = 123456
|
|
|
|
|
|
|
|
assert.Equal(t, 123456, l.PlaceID)
|
|
|
|
|
2019-12-20 11:30:58 +01:00
|
|
|
cached, err := FindLocation(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, cached.Cached)
|
|
|
|
assert.Equal(t, 189675302, cached.PlaceID)
|
2019-12-20 23:05:44 +01:00
|
|
|
assert.Equal(t, l.LocTitle, cached.LocTitle)
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.Equal(t, l.Address.Postcode, cached.Address.Postcode)
|
|
|
|
assert.Equal(t, l.Address.State, cached.Address.State)
|
|
|
|
assert.Equal(t, l.Address.CountryCode, cached.Address.CountryCode)
|
|
|
|
assert.Equal(t, l.Address.Country, cached.Address.Country)
|
|
|
|
})
|
|
|
|
|
2019-12-20 11:30:58 +01:00
|
|
|
t.Run("BerlinMuseum", func(t *testing.T) {
|
2019-12-19 17:17:13 +01:00
|
|
|
lat := 52.52057
|
2019-12-20 11:30:58 +01:00
|
|
|
lng := 13.40889
|
2019-12-19 17:17:13 +01:00
|
|
|
|
2019-12-20 11:30:58 +01:00
|
|
|
l, err := FindLocation(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.False(t, l.Cached)
|
|
|
|
assert.Equal(t, 48287001, l.PlaceID)
|
2019-12-20 23:05:44 +01:00
|
|
|
assert.Equal(t, "Menschen Museum", l.LocTitle)
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.Equal(t, "10178", l.Address.Postcode)
|
|
|
|
assert.Equal(t, "Berlin", l.Address.State)
|
|
|
|
assert.Equal(t, "de", l.Address.CountryCode)
|
|
|
|
assert.Equal(t, "Germany", l.Address.Country)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("No Location", func(t *testing.T) {
|
|
|
|
lat := 0.0
|
2019-12-20 11:30:58 +01:00
|
|
|
lng := 0.0
|
2019-12-19 17:17:13 +01:00
|
|
|
|
2019-12-20 11:30:58 +01:00
|
|
|
l, err := FindLocation(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("err should not be nil")
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:04:26 +01:00
|
|
|
assert.Equal(t, "osm: skipping lat 0.000000, lng 0.000000", err.Error())
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.False(t, l.Cached)
|
|
|
|
})
|
|
|
|
}
|