-
Notifications
You must be signed in to change notification settings - Fork 0
/
cityUpgrader_test.go
71 lines (64 loc) · 1.72 KB
/
cityUpgrader_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
package ipdb
import (
"errors"
"fmt"
"testing"
)
const STRING_BENCH_IP = "118.28.1.1"
var errUpgrader = errors.New("NIL Upgrader!")
// tests driven table
var tests = []struct {
ip string
output error
}{
// MainLand
{"124.21.1.6", ERR_NOT_FOUND_MAINLAND_REGION}, // Mainland ip without details
{"1.2.1.0", ERR_NOT_FOUND_MAINLAND_CITY}, // Mainland ip without details
{"39.135.129.64", nil}, // Mainland ip with details
// HK/TW/MO
{"61.244.148.166", nil}, // HK ip
{"23.36.143.47", nil}, // MO ip
{"114.44.227.87", nil}, // TW ip
// Foreign
{"27.116.59.8", nil}, // Foreign ip
{"57.71.47.25", nil}, // Foreign ip
{"57.70.191.25", nil}, // Foreign ip
{"35.248.7.15", nil}, // Foreign ip
{"38.76.87.25", nil}, // Foreign ip
{"5.22.191.25", nil}, // Foreign ip
{"37.0.71.25", nil}, // Foreign ip
{"57.84.143.25", nil}, // Foreign ip
{"31.209.135.25", nil}, // Foreign ip
{"43.245.59.25", nil}, // Foreign ip
{"14.128.7.25", nil}, // Foreign ip
{"57.71.47.25", nil}, // Foreign ip
{"23.208.167.25", nil}, // Foreign ip
{"31.15.119.2", nil}, // Foreign ip
// Others
{"1.2.4.8", ERR_NOT_FOUND_COUNTRY}, // Other ip
{"127.0.0.1", ERR_NOT_FOUND_COUNTRY}, // Other ip: localhost
}
func TestUpgrader(t *testing.T) {
if IPupgrader == nil {
t.Fatal(errUpgrader)
}
// testing
for i, ts := range tests {
t.Run(fmt.Sprintf("Example %d", i+1), func(t *testing.T) {
res, errRes := IPupgrader.FindCityInfo(ts.ip)
if errRes != ts.output {
t.Log(errRes)
t.Fatal(res)
}
})
}
}
func BenchmarkFindInfo(b *testing.B) {
if IPupgrader == nil {
b.Fatal(errUpgrader)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
IPupgrader.FindCityInfo(STRING_BENCH_IP)
}
}