Browse Source

Merge pull request #160 from felixonmars/fix-test

Don't copy assets if they are already present
V2Fly Team 5 years ago
parent
commit
39e9916cb5
3 changed files with 15 additions and 5 deletions
  1. 6 2
      app/router/condition_geoip_test.go
  2. 6 2
      app/router/condition_test.go
  3. 3 1
      infra/conf/dns_test.go

+ 6 - 2
app/router/condition_geoip_test.go

@@ -17,8 +17,12 @@ func init() {
 	wd, err := os.Getwd()
 	wd, err := os.Getwd()
 	common.Must(err)
 	common.Must(err)
 
 
-	common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
-	common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))
+	if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) {
+		common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
+	}
+	if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && os.IsNotExist(err) {
+		common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))
+	}
 }
 }
 
 
 func TestGeoIPMatcherContainer(t *testing.T) {
 func TestGeoIPMatcherContainer(t *testing.T) {

+ 6 - 2
app/router/condition_test.go

@@ -23,8 +23,12 @@ func init() {
 	wd, err := os.Getwd()
 	wd, err := os.Getwd()
 	common.Must(err)
 	common.Must(err)
 
 
-	common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
-	common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))
+	if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) {
+		common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
+	}
+	if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && os.IsNotExist(err) {
+		common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))
+	}
 }
 }
 
 
 func withOutbound(outbound *session.Outbound) *Context {
 func withOutbound(outbound *session.Outbound) *Context {

+ 3 - 1
infra/conf/dns_test.go

@@ -20,7 +20,9 @@ func init() {
 	wd, err := os.Getwd()
 	wd, err := os.Getwd()
 	common.Must(err)
 	common.Must(err)
 
 
-	common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
+	if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && os.IsNotExist(err) {
+		common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))
+	}
 
 
 	geositeFilePath := platform.GetAssetLocation("geosite.dat")
 	geositeFilePath := platform.GetAssetLocation("geosite.dat")
 	geositeFile, err := os.OpenFile(geositeFilePath, os.O_CREATE|os.O_WRONLY, 0600)
 	geositeFile, err := os.OpenFile(geositeFilePath, os.O_CREATE|os.O_WRONLY, 0600)