Codebase list golang-github-oschwald-geoip2-golang / upstream/1.2.1+git20190226.42d566f
Import upstream version 1.2.1+git20190226.42d566f, md5 a25fcf388a3787bafd9d558ec8cb6108 Debian Janitor 4 years ago
4 changed file(s) with 201 addition(s) and 164 deletion(s). Raw diff Collapse all Expand all
00 [submodule "test-data"]
11 path = test-data
2 url = git://github.com/maxmind/MaxMind-DB.git
2 url = https://github.com/maxmind/MaxMind-DB.git
00 language: go
11
22 go:
3 - 1.4
4 - 1.5
5 - 1.6
63 - 1.7
74 - 1.8
5 - 1.9
6 - "1.10"
7 - 1.11
8 - 1.12
89 - tip
910
1011 matrix:
1213 - go: tip
1314
1415 before_install:
15 - "if [[ $TRAVIS_GO_VERSION == 1.8 ]]; then go get -v github.com/golang/lint/golint; fi"
16 - "if [[ $TRAVIS_GO_VERSION == 1.11 ]]; then go get -u golang.org/x/lint/golint; fi"
1617
1718 script:
1819 - go test -race -cpu 1,4 -v
1920 - go test -race -v -tags appengine
20 - "if [[ $TRAVIS_GO_VERSION == 1.8 ]]; then go vet ./...; fi"
21 - "if [[ $TRAVIS_GO_VERSION == 1.8 ]]; then golint .; fi"
21 - "if [[ $TRAVIS_GO_VERSION == 1.11 ]]; then go vet ./...; fi"
22 - "if [[ $TRAVIS_GO_VERSION == 1.11 ]]; then golint .; fi"
2223
2324 sudo: false
2626 Names map[string]string `maxminddb:"names"`
2727 } `maxminddb:"continent"`
2828 Country struct {
29 GeoNameID uint `maxminddb:"geoname_id"`
30 IsoCode string `maxminddb:"iso_code"`
31 Names map[string]string `maxminddb:"names"`
29 GeoNameID uint `maxminddb:"geoname_id"`
30 IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
31 IsoCode string `maxminddb:"iso_code"`
32 Names map[string]string `maxminddb:"names"`
3233 } `maxminddb:"country"`
3334 Location struct {
3435 AccuracyRadius uint16 `maxminddb:"accuracy_radius"`
4142 Code string `maxminddb:"code"`
4243 } `maxminddb:"postal"`
4344 RegisteredCountry struct {
44 GeoNameID uint `maxminddb:"geoname_id"`
45 IsoCode string `maxminddb:"iso_code"`
46 Names map[string]string `maxminddb:"names"`
45 GeoNameID uint `maxminddb:"geoname_id"`
46 IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
47 IsoCode string `maxminddb:"iso_code"`
48 Names map[string]string `maxminddb:"names"`
4749 } `maxminddb:"registered_country"`
4850 RepresentedCountry struct {
49 GeoNameID uint `maxminddb:"geoname_id"`
50 IsoCode string `maxminddb:"iso_code"`
51 Names map[string]string `maxminddb:"names"`
52 Type string `maxminddb:"type"`
51 GeoNameID uint `maxminddb:"geoname_id"`
52 IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
53 IsoCode string `maxminddb:"iso_code"`
54 Names map[string]string `maxminddb:"names"`
55 Type string `maxminddb:"type"`
5356 } `maxminddb:"represented_country"`
5457 Subdivisions []struct {
5558 GeoNameID uint `maxminddb:"geoname_id"`
7174 Names map[string]string `maxminddb:"names"`
7275 } `maxminddb:"continent"`
7376 Country struct {
74 GeoNameID uint `maxminddb:"geoname_id"`
75 IsoCode string `maxminddb:"iso_code"`
76 Names map[string]string `maxminddb:"names"`
77 GeoNameID uint `maxminddb:"geoname_id"`
78 IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
79 IsoCode string `maxminddb:"iso_code"`
80 Names map[string]string `maxminddb:"names"`
7781 } `maxminddb:"country"`
7882 RegisteredCountry struct {
79 GeoNameID uint `maxminddb:"geoname_id"`
80 IsoCode string `maxminddb:"iso_code"`
81 Names map[string]string `maxminddb:"names"`
83 GeoNameID uint `maxminddb:"geoname_id"`
84 IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
85 IsoCode string `maxminddb:"iso_code"`
86 Names map[string]string `maxminddb:"names"`
8287 } `maxminddb:"registered_country"`
8388 RepresentedCountry struct {
84 GeoNameID uint `maxminddb:"geoname_id"`
85 IsoCode string `maxminddb:"iso_code"`
86 Names map[string]string `maxminddb:"names"`
87 Type string `maxminddb:"type"`
89 GeoNameID uint `maxminddb:"geoname_id"`
90 IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
91 IsoCode string `maxminddb:"iso_code"`
92 Names map[string]string `maxminddb:"names"`
93 Type string `maxminddb:"type"`
8894 } `maxminddb:"represented_country"`
8995 Traits struct {
9096 IsAnonymousProxy bool `maxminddb:"is_anonymous_proxy"`
44 "net"
55 "testing"
66
7 . "gopkg.in/check.v1"
7 "github.com/stretchr/testify/assert"
88 )
99
10 func TestGeoIP2(t *testing.T) { TestingT(t) }
11
12 type MySuite struct{}
13
14 var _ = Suite(&MySuite{})
15
16 func (s *MySuite) TestReader(c *C) {
10 func TestReader(t *testing.T) {
1711 reader, err := Open("test-data/test-data/GeoIP2-City-Test.mmdb")
18 c.Assert(err, IsNil)
12 assert.Nil(t, err)
1913
2014 defer reader.Close()
2115
2216 record, err := reader.City(net.ParseIP("81.2.69.160"))
23 c.Assert(err, IsNil)
17 assert.Nil(t, err)
2418
2519 m := reader.Metadata()
26 c.Assert(m.BinaryFormatMajorVersion, Equals, uint(2))
27 c.Assert(m.BinaryFormatMinorVersion, Equals, uint(0))
28 c.Assert(m.BuildEpoch, Equals, uint(0x58f5327d))
29 c.Assert(m.DatabaseType, Equals, "GeoIP2-City")
30 c.Assert(m.Description, DeepEquals, map[string]string{
31 "en": "GeoIP2 City Test Database (fake GeoIP2 data, for example purposes only)",
32 "zh": "小型数据库",
33 })
34 c.Assert(m.IPVersion, Equals, uint(6))
35 c.Assert(m.Languages, DeepEquals, []string{"en", "zh"})
36 c.Assert(m.NodeCount, Equals, uint(1240))
37 c.Assert(m.RecordSize, Equals, uint(28))
38
39 c.Assert(record.City.GeoNameID, Equals, uint(2643743))
40 c.Assert(record.City.Names, DeepEquals, map[string]string{
41 "de": "London",
42 "en": "London",
43 "es": "Londres",
44 "fr": "Londres",
45 "ja": "ロンドン",
46 "pt-BR": "Londres",
47 "ru": "Лондон",
48 })
49 c.Assert(record.Continent.GeoNameID, Equals, uint(6255148))
50 c.Assert(record.Continent.Code, Equals, "EU")
51 c.Assert(record.Continent.Names, DeepEquals, map[string]string{
52 "de": "Europa",
53 "en": "Europe",
54 "es": "Europa",
55 "fr": "Europe",
56 "ja": "ヨーロッパ",
57 "pt-BR": "Europa",
58 "ru": "Европа",
59 "zh-CN": "欧洲",
60 })
61
62 c.Assert(record.Country.GeoNameID, Equals, uint(2635167))
63 c.Assert(record.Country.IsoCode, Equals, "GB")
64 c.Assert(record.Country.Names, DeepEquals, map[string]string{
65 "de": "Vereinigtes Königreich",
66 "en": "United Kingdom",
67 "es": "Reino Unido",
68 "fr": "Royaume-Uni",
69 "ja": "イギリス",
70 "pt-BR": "Reino Unido",
71 "ru": "Великобритания",
72 "zh-CN": "英国",
73 })
74
75 c.Assert(record.Location.AccuracyRadius, Equals, uint16(100))
76 c.Assert(record.Location.Latitude, Equals, 51.5142)
77 c.Assert(record.Location.Longitude, Equals, -0.0931)
78 c.Assert(record.Location.TimeZone, Equals, "Europe/London")
79
80 c.Assert(record.Subdivisions[0].GeoNameID, Equals, uint(6269131))
81 c.Assert(record.Subdivisions[0].IsoCode, Equals, "ENG")
82 c.Assert(record.Subdivisions[0].Names, DeepEquals, map[string]string{
83 "en": "England",
84 "pt-BR": "Inglaterra",
85 "fr": "Angleterre",
86 "es": "Inglaterra",
87 })
88
89 c.Assert(record.RegisteredCountry.GeoNameID, Equals, uint(6252001))
90 c.Assert(record.RegisteredCountry.IsoCode, Equals, "US")
91 c.Assert(record.RegisteredCountry.Names, DeepEquals, map[string]string{
92 "de": "USA",
93 "en": "United States",
94 "es": "Estados Unidos",
95 "fr": "États-Unis",
96 "ja": "アメリカ合衆国",
97 "pt-BR": "Estados Unidos",
98 "ru": "США",
99 "zh-CN": "美国",
100 })
101 }
102
103 func (s *MySuite) TestMetroCode(c *C) {
20 assert.Equal(t, uint(2), m.BinaryFormatMajorVersion)
21 assert.Equal(t, uint(0), m.BinaryFormatMinorVersion)
22 assert.NotZero(t, m.BuildEpoch)
23 assert.Equal(t, "GeoIP2-City", m.DatabaseType)
24 assert.Equal(t,
25 map[string]string{
26 "en": "GeoIP2 City Test Database (fake GeoIP2 data, for example purposes only)",
27 "zh": "小型数据库",
28 },
29 m.Description,
30 )
31 assert.Equal(t, uint(6), m.IPVersion)
32 assert.Equal(t, []string{"en", "zh"}, m.Languages)
33 assert.NotZero(t, m.NodeCount)
34 assert.Equal(t, uint(28), m.RecordSize)
35
36 assert.Equal(t, uint(2643743), record.City.GeoNameID)
37 assert.Equal(t,
38 map[string]string{
39 "de": "London",
40 "en": "London",
41 "es": "Londres",
42 "fr": "Londres",
43 "ja": "ロンドン",
44 "pt-BR": "Londres",
45 "ru": "Лондон",
46 },
47 record.City.Names,
48 )
49 assert.Equal(t, uint(6255148), record.Continent.GeoNameID)
50 assert.Equal(t, "EU", record.Continent.Code)
51 assert.Equal(t,
52 map[string]string{
53 "de": "Europa",
54 "en": "Europe",
55 "es": "Europa",
56 "fr": "Europe",
57 "ja": "ヨーロッパ",
58 "pt-BR": "Europa",
59 "ru": "Европа",
60 "zh-CN": "欧洲",
61 },
62 record.Continent.Names,
63 )
64
65 assert.Equal(t, uint(2635167), record.Country.GeoNameID)
66 assert.True(t, record.Country.IsInEuropeanUnion)
67 assert.Equal(t, "GB", record.Country.IsoCode)
68 assert.Equal(t,
69 map[string]string{
70 "de": "Vereinigtes Königreich",
71 "en": "United Kingdom",
72 "es": "Reino Unido",
73 "fr": "Royaume-Uni",
74 "ja": "イギリス",
75 "pt-BR": "Reino Unido",
76 "ru": "Великобритания",
77 "zh-CN": "英国",
78 },
79 record.Country.Names,
80 )
81
82 assert.Equal(t, uint16(100), record.Location.AccuracyRadius)
83 assert.Equal(t, 51.5142, record.Location.Latitude)
84 assert.Equal(t, -0.0931, record.Location.Longitude)
85 assert.Equal(t, "Europe/London", record.Location.TimeZone)
86
87 assert.Equal(t, uint(6269131), record.Subdivisions[0].GeoNameID)
88 assert.Equal(t, "ENG", record.Subdivisions[0].IsoCode)
89 assert.Equal(t,
90 map[string]string{
91 "en": "England",
92 "pt-BR": "Inglaterra",
93 "fr": "Angleterre",
94 "es": "Inglaterra",
95 },
96 record.Subdivisions[0].Names,
97 )
98
99 assert.Equal(t, uint(6252001), record.RegisteredCountry.GeoNameID)
100 assert.False(t, record.RegisteredCountry.IsInEuropeanUnion)
101 assert.Equal(t, "US", record.RegisteredCountry.IsoCode)
102 assert.Equal(t,
103 map[string]string{
104 "de": "USA",
105 "en": "United States",
106 "es": "Estados Unidos",
107 "fr": "États-Unis",
108 "ja": "アメリカ合衆国",
109 "pt-BR": "Estados Unidos",
110 "ru": "США",
111 "zh-CN": "美国",
112 },
113 record.RegisteredCountry.Names,
114 )
115
116 assert.False(t, record.RepresentedCountry.IsInEuropeanUnion)
117 }
118
119 func TestMetroCode(t *testing.T) {
104120 reader, err := Open("test-data/test-data/GeoIP2-City-Test.mmdb")
105 c.Assert(err, IsNil)
121 assert.Nil(t, err)
106122 defer reader.Close()
107123
108124 record, err := reader.City(net.ParseIP("216.160.83.56"))
109 c.Assert(err, IsNil)
110
111 c.Assert(record.Location.MetroCode, Equals, uint(819))
112 }
113
114 func (s *MySuite) TestAnonymousIP(c *C) {
125 assert.Nil(t, err)
126
127 assert.Equal(t, uint(819), record.Location.MetroCode)
128 }
129
130 func TestAnonymousIP(t *testing.T) {
115131 reader, err := Open("test-data/test-data/GeoIP2-Anonymous-IP-Test.mmdb")
116 c.Assert(err, IsNil)
132 assert.Nil(t, err)
117133 defer reader.Close()
118134
119135 record, err := reader.AnonymousIP(net.ParseIP("1.2.0.0"))
120 c.Assert(err, IsNil)
121
122 c.Assert(record.IsAnonymous, Equals, true)
123
124 c.Assert(record.IsAnonymousVPN, Equals, true)
125 c.Assert(record.IsHostingProvider, Equals, false)
126 c.Assert(record.IsPublicProxy, Equals, false)
127 c.Assert(record.IsTorExitNode, Equals, false)
128 }
129
130 func (s *MySuite) TestASN(c *C) {
136 assert.Nil(t, err)
137
138 assert.Equal(t, true, record.IsAnonymous)
139
140 assert.Equal(t, true, record.IsAnonymousVPN)
141 assert.Equal(t, false, record.IsHostingProvider)
142 assert.Equal(t, false, record.IsPublicProxy)
143 assert.Equal(t, false, record.IsTorExitNode)
144 }
145
146 func TestASN(t *testing.T) {
131147 reader, err := Open("test-data/test-data/GeoLite2-ASN-Test.mmdb")
132 c.Assert(err, IsNil)
148 assert.Nil(t, err)
133149 defer reader.Close()
134150
135151 record, err := reader.ASN(net.ParseIP("1.128.0.0"))
136 c.Assert(err, IsNil)
137
138 c.Assert(record.AutonomousSystemNumber, Equals, uint(1221))
139
140 c.Assert(record.AutonomousSystemOrganization, Equals, "Telstra Pty Ltd")
141 }
142
143 func (s *MySuite) TestConnectionType(c *C) {
152 assert.Nil(t, err)
153
154 assert.Equal(t, uint(1221), record.AutonomousSystemNumber)
155
156 assert.Equal(t, "Telstra Pty Ltd", record.AutonomousSystemOrganization)
157 }
158
159 func TestConnectionType(t *testing.T) {
144160 reader, err := Open("test-data/test-data/GeoIP2-Connection-Type-Test.mmdb")
145 c.Assert(err, IsNil)
161 assert.Nil(t, err)
146162
147163 defer reader.Close()
148164
149165 record, err := reader.ConnectionType(net.ParseIP("1.0.1.0"))
150 c.Assert(err, IsNil)
151
152 c.Assert(record.ConnectionType, Equals, "Cable/DSL")
153 }
154
155 func (s *MySuite) TestDomain(c *C) {
166 assert.Nil(t, err)
167
168 assert.Equal(t, "Cable/DSL", record.ConnectionType)
169 }
170
171 func TestCountry(t *testing.T) {
172 reader, err := Open("test-data/test-data/GeoIP2-Country-Test.mmdb")
173 assert.Nil(t, err)
174
175 defer reader.Close()
176
177 record, err := reader.Country(net.ParseIP("81.2.69.160"))
178 assert.Nil(t, err)
179
180 assert.True(t, record.Country.IsInEuropeanUnion)
181 assert.False(t, record.RegisteredCountry.IsInEuropeanUnion)
182 assert.False(t, record.RepresentedCountry.IsInEuropeanUnion)
183 }
184
185 func TestDomain(t *testing.T) {
156186 reader, err := Open("test-data/test-data/GeoIP2-Domain-Test.mmdb")
157 c.Assert(err, IsNil)
187 assert.Nil(t, err)
158188 defer reader.Close()
159189
160190 record, err := reader.Domain(net.ParseIP("1.2.0.0"))
161 c.Assert(err, IsNil)
162 c.Assert(record.Domain, Equals, "maxmind.com")
163 }
164
165 func (s *MySuite) TestISP(c *C) {
191 assert.Nil(t, err)
192 assert.Equal(t, "maxmind.com", record.Domain)
193 }
194
195 func TestISP(t *testing.T) {
166196 reader, err := Open("test-data/test-data/GeoIP2-ISP-Test.mmdb")
167 c.Assert(err, IsNil)
197 assert.Nil(t, err)
168198 defer reader.Close()
169199
170200 record, err := reader.ISP(net.ParseIP("1.128.0.0"))
171 c.Assert(err, IsNil)
172
173 c.Assert(record.AutonomousSystemNumber, Equals, uint(1221))
174
175 c.Assert(record.AutonomousSystemOrganization, Equals, "Telstra Pty Ltd")
176 c.Assert(record.ISP, Equals, "Telstra Internet")
177 c.Assert(record.Organization, Equals, "Telstra Internet")
201 assert.Nil(t, err)
202
203 assert.Equal(t, uint(1221), record.AutonomousSystemNumber)
204
205 assert.Equal(t, "Telstra Pty Ltd", record.AutonomousSystemOrganization)
206 assert.Equal(t, "Telstra Internet", record.ISP)
207 assert.Equal(t, "Telstra Internet", record.Organization)
178208 }
179209
180210 // This ensures the compiler does not optimize away the function call