@@ -3,7 +3,6 @@ package geoip2
33import (
44 "net"
55 "testing"
6- "time"
76)
87
98func TestReader (t * testing.T ) {
@@ -71,95 +70,6 @@ func TestReader(t *testing.T) {
7170 }
7271}
7372
74- func TestDomain (t * testing.T ) {
75- reader , err := NewDomainReaderFromFile ("testdata/GeoIP2-Domain-Test.mmdb" )
76- if err != nil {
77- t .Fatal (err )
78- }
79- record , err := reader .Lookup (net .ParseIP ("1.2.0.0" ))
80- if err != nil {
81- t .Fatal (err )
82- }
83- if record != "maxmind.com" {
84- t .Fatal ()
85- }
86- }
87-
88- func TestAnonymousIP (t * testing.T ) {
89- reader , err := NewAnonymousIPReaderFromFile ("testdata/GeoIP2-Anonymous-IP-Test.mmdb" )
90- if err != nil {
91- t .Fatal (err )
92- }
93- record , err := reader .Lookup (net .ParseIP ("1.2.0.0" ))
94- if err != nil {
95- t .Fatal (err )
96- }
97- if record .IsAnonymous != true {
98- t .Fatal ()
99- }
100- if record .IsAnonymousVPN != true {
101- t .Fatal ()
102- }
103- if record .IsHostingProvider != false {
104- t .Fatal ()
105- }
106- if record .IsPublicProxy != false {
107- t .Fatal ()
108- }
109- if record .IsTorExitNode != false {
110- t .Fatal ()
111- }
112- }
113-
114- func TestEnterprise (t * testing.T ) {
115- reader , err := NewEnterpriseReaderFromFile ("testdata/GeoIP2-Enterprise-Test.mmdb" )
116- if err != nil {
117- t .Fatal (err )
118- }
119- record , err := reader .Lookup (net .ParseIP ("74.209.24.0" ))
120- if err != nil {
121- t .Fatal (err )
122- }
123- if record .City .Confidence != 11 {
124- t .Fatal ()
125- }
126- if record .Traits .AutonomousSystemNumber != 14671 {
127- t .Fatal ()
128- }
129- if record .Traits .AutonomousSystemOrganization != "FairPoint Communications" {
130- t .Fatal ()
131- }
132- if record .Traits .ConnectionType != "Cable/DSL" {
133- t .Fatal ()
134- }
135- if record .Traits .Domain != "frpt.net" {
136- t .Fatal ()
137- }
138- if record .Traits .StaticIPScore != 0.34 {
139- t .Fatal ()
140- }
141- }
142-
143- func TestBench (t * testing.T ) {
144- reader , err := NewCityReaderFromFile ("testdata/GeoIP2-City.mmdb" )
145- if err != nil {
146- t .Fatal (err )
147- }
148- ip := net .ParseIP ("81.2.69.142" )
149- var minDuration time.Duration
150- for i := 0 ; i < 200 ; i ++ {
151- start := time .Now ()
152- for j := 0 ; j < 10000 ; j ++ {
153- _ , _ = reader .Lookup (ip )
154- }
155- duration := time .Since (start )
156- if minDuration == 0 || minDuration > duration {
157- minDuration = duration
158- }
159- }
160- t .Log (int (minDuration / 10000 ), "ns/op" )
161- }
162-
16373func BenchmarkGeoIP2 (b * testing.B ) {
16474 ip := net .ParseIP ("81.2.69.142" )
16575 b .ReportAllocs ()
0 commit comments