Add test to ParaseIPList

This commit is contained in:
秋のかえで 2021-04-08 13:25:22 +08:00
parent 44317bd657
commit 5d5beb2028
No known key found for this signature in database
GPG key ID: C687746B27587C0D

View file

@ -25,6 +25,27 @@ func init() {
}
}
func TestParaseIPList(t *testing.T) {
t.Log(os.Getenv("xray.location.asset"))
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoiptestrouter.dat"), platform.GetAssetLocation("geoip.dat")))
ips := []string{
"geoip:us",
"geoip:cn",
"geoip:!cn",
"ext:geoiptestrouter.dat:!cn",
"ext:geoiptestrouter.dat:ca",
"ext-ip:geoiptestrouter.dat:!cn",
"ext-ip:geoiptestrouter.dat:!ca",
}
_, err := ParaseIPList(ips)
if err != nil {
t.Fatalf("Failed to parse geoip list, got %s", err)
}
}
func TestGeoIPMatcherContainer(t *testing.T) {
container := &GeoIPMatcherContainer{}
@ -123,18 +144,6 @@ func TestGeoIPMatcher(t *testing.T) {
}
}
func TestGeoIPMatcher4CN(t *testing.T) {
ips, err := loadGeoIP("CN")
common.Must(err)
matcher := &GeoIPMatcher{}
common.Must(matcher.Init(ips))
if matcher.Match([]byte{8, 8, 8, 8}) {
t.Error("expect CN geoip doesn't contain 8.8.8.8, but actually does")
}
}
func TestGeoIPReverseMatcher(t *testing.T) {
cidrList := CIDRList{
{Ip: []byte{8, 8, 8, 8}, Prefix: 32},
@ -171,6 +180,18 @@ func TestGeoIPReverseMatcher(t *testing.T) {
}
}
func TestGeoIPMatcher4CN(t *testing.T) {
ips, err := loadGeoIP("CN")
common.Must(err)
matcher := &GeoIPMatcher{}
common.Must(matcher.Init(ips))
if matcher.Match([]byte{8, 8, 8, 8}) {
t.Error("expect CN geoip doesn't contain 8.8.8.8, but actually does")
}
}
func TestGeoIPMatcher6US(t *testing.T) {
ips, err := loadGeoIP("US")
common.Must(err)