-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikipedia_test.go
52 lines (43 loc) · 1.42 KB
/
wikipedia_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
package geonames_test
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/qba73/geonames"
)
func TestGetPlace_RetrievesSingleGeoNameOnValidInput(t *testing.T) {
t.Parallel()
testFile := "testdata/response-geoname-wikipedia-single.json"
wantReqURI := "/wikipediaSearchJSON?q=Castlebar&title=Castlebar&countryCode=IE&maxRows=1&username=DummyUser"
ts := newTestServer(testFile, wantReqURI, t)
defer ts.Close()
client := geonames.NewClient("DummyUser")
client.BaseURL = ts.URL
name := "Castlebar"
country := "IE"
resultLimit := 1
got, err := client.GetPlace(context.Background(), name, country, resultLimit)
if err != nil {
t.Fatal(err)
}
want := []geonames.Geoname{
{
Summary: "Castlebar is the county town of County Mayo, Ireland. It is in the middle of the county and is its largest town by population. A campus of Galway-Mayo Institute of Technology and the Country Life section of the National Museum of Ireland are two important local amenities (...)",
Elevation: 41,
GeoNameID: 2965654,
Position: geonames.Position{
Lat: 53.8608,
Lng: -9.2988,
},
CountryCode: "IE",
Rank: 100,
Language: "en",
Title: "Castlebar",
URL: "en.wikipedia.org/wiki/Castlebar",
},
}
if !cmp.Equal(want, got, cmpopts.IgnoreFields(geonames.Geoname{}, "Summary", "Position")) {
t.Errorf(cmp.Diff(want, got))
}
}