-
Notifications
You must be signed in to change notification settings - Fork 49
/
city_test.go
76 lines (61 loc) · 1.17 KB
/
city_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
package ipdb
import (
"testing"
)
var db *City
func init() {
db, _ = NewCity("city.free.ipdb")
}
func TestNewCity(t *testing.T) {
db, err := NewCity("city.free.ipdb")
if err != nil {
t.Log(err)
}
t.Log(db.BuildTime())
t.Log(db.Fields())
loc, err := db.Find("1.1.1.1", "CN")
if err != nil {
t.Log(err)
} else {
t.Log(loc)
}
m, err := db.FindMap("27.190.250.164", "CN")
if err == nil {
for k, v := range m {
t.Log(k, v)
}
}
info1, err := db.FindInfo("1.1.1.1", "CN")
if err == nil {
for _, item := range info1.ASNInfo {
t.Log(item.ASN, item.Registry, item.Country, item.Net, item.Org)
}
}
info, err := db.FindInfo("27.190.250.164", "CN")
if err != nil {
t.Log(err)
} else {
t.Log(info.Route)
t.Log(info.ASN)
t.Log(info.DistrictInfo)
t.Log(info.ASNInfo)
for _, af := range info.ASNInfo {
t.Log(af)
}
}
}
func BenchmarkCity_Find(b *testing.B) {
for i := 0; i < b.N; i++ {
db.Find("118.28.1.1", "CN")
}
}
func BenchmarkCity_FindMap(b *testing.B) {
for i := 0; i < b.N; i++ {
db.FindMap("118.28.1.1", "CN")
}
}
func BenchmarkCity_FindInfo(b *testing.B) {
for i := 0; i < b.N; i++ {
db.FindInfo("118.28.1.1", "CN")
}
}