-
Notifications
You must be signed in to change notification settings - Fork 5
/
geonames_test.go
212 lines (184 loc) · 5.53 KB
/
geonames_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package geonames
import (
"fmt"
"github.com/asaskevich/govalidator"
"github.com/mkrou/geonames/models"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func validate(x interface{}) error {
_, err := govalidator.ValidateStruct(x)
return err
}
func integration(t *testing.T, kind string, f func(p Parser) error) {
Convey("Given a default parser", t, func() {
p := NewParser()
Convey(fmt.Sprintf("When %s are parsed", kind), func() {
err := f(p)
Convey("The error should be nill", func() {
So(err, ShouldBeNil)
})
})
})
}
func TestIntegrationParser_GetAlternames(t *testing.T) {
integration(t, "alternames", func(p Parser) error {
return p.GetAlternateNames(AlternateNames, func(x *models.AlternateName) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetAlphabeticalAlternames(t *testing.T) {
integration(t, "alternames", func(p Parser) error {
return p.GetAlternateNames("alternatenames/AD.zip", func(x *models.AlternateName) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonames500(t *testing.T) {
integration(t, "all cities with a population > 500", func(p Parser) error {
return p.GetGeonames(Cities500, func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonames1000(t *testing.T) {
integration(t, "all cities with a population > 1000", func(p Parser) error {
return p.GetGeonames(Cities1000, func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonames5000(t *testing.T) {
integration(t, "all cities with a population > 5000", func(p Parser) error {
return p.GetGeonames(Cities5000, func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonames15000(t *testing.T) {
integration(t, "all cities with a population > 15000", func(p Parser) error {
return p.GetGeonames(Cities15000, func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonamesAll(t *testing.T) {
integration(t, "all cities in all countries", func(p Parser) error {
return p.GetGeonames(AllCountries, func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonamesWithoutCountry(t *testing.T) {
integration(t, "all cities without countries", func(p Parser) error {
return p.GetGeonames(NoCountry, func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetGeonamesAlphabetical(t *testing.T) {
integration(t, "all cities that start with AD", func(p Parser) error {
return p.GetGeonames("AD.zip", func(x *models.Geoname) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetLanguages(t *testing.T) {
integration(t, "languages", func(p Parser) error {
return p.GetLanguages(func(x *models.Language) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetTimeZones(t *testing.T) {
integration(t, "time zones", func(p Parser) error {
return p.GetTimeZones(func(x *models.TimeZone) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetCountries(t *testing.T) {
integration(t, "countries", func(p Parser) error {
return p.GetCountries(func(x *models.Country) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetFeatureCodes(t *testing.T) {
integration(t, "abc", func(p Parser) error {
return p.GetFeatureCodes(FeatureCodeRu, func(x *models.FeatureCode) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetHierarchy(t *testing.T) {
integration(t, "hierarchies", func(p Parser) error {
return p.GetHierarchy(func(x *models.Hierarchy) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetShapes(t *testing.T) {
integration(t, "shapes", func(p Parser) error {
return p.GetShapes(func(x *models.Shape) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetUserTags(t *testing.T) {
integration(t, "user tags", func(p Parser) error {
return p.GetUserTags(func(x *models.UserTag) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetAdminDivisions(t *testing.T) {
integration(t, "admin divisions", func(p Parser) error {
return p.GetAdminDivisions(func(x *models.AdminDivision) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetAdminSubDivisions(t *testing.T) {
integration(t, "admin sub divisions", func(p Parser) error {
return p.GetAdminSubdivisions(func(x *models.AdminSubdivision) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetAdminCode5(t *testing.T) {
integration(t, "new admin codes", func(p Parser) error {
return p.GetAdminCodes5(func(x *models.AdminCode5) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetAlternameDeletes(t *testing.T) {
integration(t, "altername deletes", func(p Parser) error {
return p.GetAlternateNameDeletes(func(x *models.AlternateNameDelete) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetAlternameModifications(t *testing.T) {
integration(t, "altername modifications", func(p Parser) error {
return p.GetAlternateNameModifications(func(x *models.AlternateNameModification) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetDeletes(t *testing.T) {
integration(t, "deletes", func(p Parser) error {
return p.GetDeletes(func(x *models.GeonameDelete) error {
return validate(x)
})
})
}
func TestIntegrationParser_GetModifications(t *testing.T) {
integration(t, "modifications", func(p Parser) error {
return p.GetModifications(func(x *models.Geoname) error {
return validate(x)
})
})
}