mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
Revert "Refine geodata related tests (#967)"
This reverts commit 7805ca2a
This commit is contained in:
parent
70245fd30e
commit
ace2c44c2b
@ -20,10 +20,11 @@ func init() {
|
|||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||||
|
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||||
|
|
||||||
os.Setenv("v2ray.location.asset", tempPath)
|
os.Setenv("v2ray.location.asset", tempPath)
|
||||||
|
|
||||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
|
|
||||||
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||||
@ -31,6 +32,7 @@ func init() {
|
|||||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeoIPMatcherContainer(t *testing.T) {
|
func TestGeoIPMatcherContainer(t *testing.T) {
|
||||||
container := &router.GeoIPMatcherContainer{}
|
container := &router.GeoIPMatcherContainer{}
|
||||||
|
@ -26,17 +26,21 @@ func init() {
|
|||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||||
|
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||||
|
geositePath := filepath.Join(tempPath, "geosite.dat")
|
||||||
|
|
||||||
os.Setenv("v2ray.location.asset", tempPath)
|
os.Setenv("v2ray.location.asset", tempPath)
|
||||||
|
|
||||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
geositePath := platform.GetAssetLocation("geosite.dat")
|
|
||||||
|
|
||||||
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
if _, err := os.Stat(geositePath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(geositePath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
||||||
@ -44,6 +48,7 @@ func init() {
|
|||||||
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func withBackground() routing.Context {
|
func withBackground() routing.Context {
|
||||||
return &routing_session.Context{}
|
return &routing_session.Context{}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package geodata_test
|
package geodata_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v4/common"
|
"github.com/v2fly/v2ray-core/v4/common"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/geodata"
|
"github.com/v2fly/v2ray-core/v4/common/geodata"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/platform"
|
"github.com/v2fly/v2ray-core/v4/common/platform"
|
||||||
@ -24,24 +25,29 @@ func init() {
|
|||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||||
|
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||||
|
geositePath := filepath.Join(tempPath, "geosite.dat")
|
||||||
|
|
||||||
os.Setenv("v2ray.location.asset", tempPath)
|
os.Setenv("v2ray.location.asset", tempPath)
|
||||||
|
|
||||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
|
||||||
geositePath := platform.GetAssetLocation("geosite.dat")
|
|
||||||
|
|
||||||
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
|
|
||||||
|
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
|
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
if _, err := os.Stat(geositePath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(geositePath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
|
||||||
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDecodeGeoIP(t *testing.T) {
|
func TestDecodeGeoIP(t *testing.T) {
|
||||||
filename := platform.GetAssetLocation("geoip.dat")
|
filename := platform.GetAssetLocation("geoip.dat")
|
||||||
@ -51,7 +57,7 @@ func TestDecodeGeoIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected := []byte{10, 4, 84, 69, 83, 84, 18, 8, 10, 4, 127, 0, 0, 0, 16, 8}
|
expected := []byte{10, 4, 84, 69, 83, 84, 18, 8, 10, 4, 127, 0, 0, 0, 16, 8}
|
||||||
if !bytes.Equal(result, expected) {
|
if cmp.Diff(result, expected) != "" {
|
||||||
t.Errorf("failed to load geoip:test, expected: %v, got: %v", expected, result)
|
t.Errorf("failed to load geoip:test, expected: %v, got: %v", expected, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +70,7 @@ func TestDecodeGeoSite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected := []byte{10, 4, 84, 69, 83, 84, 18, 20, 8, 3, 18, 16, 116, 101, 115, 116, 46, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109}
|
expected := []byte{10, 4, 84, 69, 83, 84, 18, 20, 8, 3, 18, 16, 116, 101, 115, 116, 46, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109}
|
||||||
if !bytes.Equal(result, expected) {
|
if cmp.Diff(result, expected) != "" {
|
||||||
t.Errorf("failed to load geosite:test, expected: %v, got: %v", expected, result)
|
t.Errorf("failed to load geosite:test, expected: %v, got: %v", expected, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,21 @@ func init() {
|
|||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||||
|
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||||
|
geositePath := filepath.Join(tempPath, "geosite.dat")
|
||||||
|
|
||||||
os.Setenv("v2ray.location.asset", tempPath)
|
os.Setenv("v2ray.location.asset", tempPath)
|
||||||
|
|
||||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
geositePath := platform.GetAssetLocation("geosite.dat")
|
|
||||||
|
|
||||||
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
if _, err := os.Stat(geositePath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(geositePath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
||||||
@ -41,6 +45,7 @@ func init() {
|
|||||||
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDNSConfigParsing(t *testing.T) {
|
func TestDNSConfigParsing(t *testing.T) {
|
||||||
parserCreator := func() func(string) (protoiface.MessageV1, error) {
|
parserCreator := func() func(string) (protoiface.MessageV1, error) {
|
||||||
|
@ -24,17 +24,20 @@ func init() {
|
|||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||||
|
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||||
|
|
||||||
os.Setenv("v2ray.location.asset", tempPath)
|
os.Setenv("v2ray.location.asset", tempPath)
|
||||||
|
|
||||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
|
||||||
|
|
||||||
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
|
||||||
common.Must(os.MkdirAll(tempPath, 0755))
|
common.Must(os.MkdirAll(tempPath, 0755))
|
||||||
|
|
||||||
|
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
|
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//go:linkname toCidrList github.com/v2fly/v2ray-core/v4/infra/conf.toCidrList
|
//go:linkname toCidrList github.com/v2fly/v2ray-core/v4/infra/conf.toCidrList
|
||||||
func toCidrList(ips StringList) ([]*router.GeoIP, error)
|
func toCidrList(ips StringList) ([]*router.GeoIP, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user