From d9ce03d25be959f19875f1a60872f405451f0eb5 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 7 Nov 2017 16:21:36 +0100 Subject: [PATCH] test case for geoip:cn --- common/net/ipnet_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/net/ipnet_test.go b/common/net/ipnet_test.go index 572c4ed18..2943e59a6 100644 --- a/common/net/ipnet_test.go +++ b/common/net/ipnet_test.go @@ -52,6 +52,21 @@ func TestIPNet(t *testing.T) { assert(ipNet.Contains(ParseIP("91.108.255.254")), IsTrue) } +func TestGeoIPCN(t *testing.T) { + assert := With(t) + common.Must(sysio.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", "tools", "release", "config", "geoip.dat"))) + + ips, err := loadGeoIP("CN") + common.Must(err) + + ipNet := NewIPNetTable() + for _, ip := range ips { + ipNet.AddIP(ip.Ip, byte(ip.Prefix)) + } + + assert(ipNet.Contains([]byte{8, 8, 8, 8}), IsFalse) +} + func loadGeoIP(country string) ([]*router.CIDR, error) { geoipBytes, err := sysio.ReadAsset("geoip.dat") if err != nil {