mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
Refine geodata related tests (#967)
This commit is contained in:
parent
de71e63893
commit
7805ca2ac1
@ -20,18 +20,16 @@ func init() {
|
||||
common.Must(err)
|
||||
|
||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||
|
||||
os.Setenv("v2ray.location.asset", tempPath)
|
||||
|
||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
||||
|
||||
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||
common.Must(err)
|
||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeoIPMatcherContainer(t *testing.T) {
|
||||
|
@ -26,28 +26,23 @@ func init() {
|
||||
common.Must(err)
|
||||
|
||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||
geositePath := filepath.Join(tempPath, "geosite.dat")
|
||||
|
||||
os.Setenv("v2ray.location.asset", tempPath)
|
||||
|
||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||
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))
|
||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||
common.Must(err)
|
||||
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) {
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
||||
common.Must(err)
|
||||
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func withBackground() routing.Context {
|
||||
|
@ -1,14 +1,13 @@
|
||||
package geodata_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/v2fly/v2ray-core/v4/common"
|
||||
"github.com/v2fly/v2ray-core/v4/common/geodata"
|
||||
"github.com/v2fly/v2ray-core/v4/common/platform"
|
||||
@ -25,28 +24,23 @@ func init() {
|
||||
common.Must(err)
|
||||
|
||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||
geositePath := filepath.Join(tempPath, "geosite.dat")
|
||||
|
||||
os.Setenv("v2ray.location.asset", tempPath)
|
||||
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geoipPath := platform.GetAssetLocation("geoip.dat")
|
||||
geositePath := platform.GetAssetLocation("geosite.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) {
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||
common.Must(err)
|
||||
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) {
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
||||
common.Must(err)
|
||||
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeGeoIP(t *testing.T) {
|
||||
@ -57,7 +51,7 @@ func TestDecodeGeoIP(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := []byte{10, 4, 84, 69, 83, 84, 18, 8, 10, 4, 127, 0, 0, 0, 16, 8}
|
||||
if cmp.Diff(result, expected) != "" {
|
||||
if !bytes.Equal(result, expected) {
|
||||
t.Errorf("failed to load geoip:test, expected: %v, got: %v", expected, result)
|
||||
}
|
||||
}
|
||||
@ -70,7 +64,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}
|
||||
if cmp.Diff(result, expected) != "" {
|
||||
if !bytes.Equal(result, expected) {
|
||||
t.Errorf("failed to load geosite:test, expected: %v, got: %v", expected, result)
|
||||
}
|
||||
}
|
||||
|
@ -23,28 +23,23 @@ func init() {
|
||||
common.Must(err)
|
||||
|
||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||
geositePath := filepath.Join(tempPath, "geosite.dat")
|
||||
|
||||
os.Setenv("v2ray.location.asset", tempPath)
|
||||
|
||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||
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))
|
||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||
common.Must(err)
|
||||
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) {
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geositeBytes, err := common.FetchHTTPContent(geositeURL)
|
||||
common.Must(err)
|
||||
common.Must(filesystem.WriteFile(geositePath, geositeBytes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDNSConfigParsing(t *testing.T) {
|
||||
|
@ -24,19 +24,16 @@ func init() {
|
||||
common.Must(err)
|
||||
|
||||
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
|
||||
geoipPath := filepath.Join(tempPath, "geoip.dat")
|
||||
|
||||
os.Setenv("v2ray.location.asset", tempPath)
|
||||
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
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) {
|
||||
common.Must(os.MkdirAll(tempPath, 0755))
|
||||
geoipBytes, err := common.FetchHTTPContent(geoipURL)
|
||||
common.Must(err)
|
||||
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//go:linkname toCidrList github.com/v2fly/v2ray-core/v4/infra/conf.toCidrList
|
||||
|
Loading…
Reference in New Issue
Block a user