mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
fix temp file generation
This commit is contained in:
parent
03d8c33fd1
commit
7632618584
@ -9,19 +9,40 @@ import (
|
|||||||
|
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"sync"
|
||||||
_ "v2ray.com/core"
|
_ "v2ray.com/core"
|
||||||
|
"v2ray.com/core/common/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
runningServers = make([]*exec.Cmd, 0, 10)
|
runningServers = make([]*exec.Cmd, 0, 10)
|
||||||
|
testBinaryPath string
|
||||||
|
testBinaryPathGen sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTestBinaryPath() string {
|
func GenTestBinaryPath() {
|
||||||
file := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "v2ray.test")
|
testBinaryPathGen.Do(func() {
|
||||||
|
var tempDir string
|
||||||
|
err := retry.Timed(5, 100).On(func() error {
|
||||||
|
dir, err := ioutil.TempDir("", "v2ray")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tempDir = dir
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
file := filepath.Join(tempDir, "v2ray.test")
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
file += ".exe"
|
file += ".exe"
|
||||||
}
|
}
|
||||||
return file
|
testBinaryPath = file
|
||||||
|
fmt.Printf("Generated binary path: %s\n", file)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSourcePath() string {
|
func GetSourcePath() string {
|
||||||
|
@ -11,21 +11,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BuildV2Ray() error {
|
func BuildV2Ray() error {
|
||||||
binaryPath := GetTestBinaryPath()
|
GenTestBinaryPath()
|
||||||
if _, err := os.Stat(binaryPath); err == nil {
|
if _, err := os.Stat(testBinaryPath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("go", "test", "-tags", "json coverage coveragemain", "-coverpkg", "v2ray.com/core/...", "-c", "-o", binaryPath, GetSourcePath())
|
cmd := exec.Command("go", "test", "-tags", "json coverage coveragemain", "-coverpkg", "v2ray.com/core/...", "-c", "-o", testBinaryPath, GetSourcePath())
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunV2Ray(configFile string) *exec.Cmd {
|
func RunV2Ray(configFile string) *exec.Cmd {
|
||||||
binaryPath := GetTestBinaryPath()
|
GenTestBinaryPath()
|
||||||
|
|
||||||
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
|
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
|
||||||
profile := uuid.New().String() + ".out"
|
profile := uuid.New().String() + ".out"
|
||||||
proc := exec.Command(binaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
|
proc := exec.Command(testBinaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
|
||||||
proc.Stderr = os.Stderr
|
proc.Stderr = os.Stderr
|
||||||
proc.Stdout = os.Stdout
|
proc.Stdout = os.Stdout
|
||||||
|
|
||||||
|
@ -3,23 +3,25 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildV2Ray() error {
|
func BuildV2Ray() error {
|
||||||
binaryPath := GetTestBinaryPath()
|
GenTestBinaryPath()
|
||||||
if _, err := os.Stat(binaryPath); err == nil {
|
if _, err := os.Stat(testBinaryPath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("go", "build", "-tags=json", "-o="+binaryPath, GetSourcePath())
|
fmt.Printf("Building V2Ray into path (%d)\n", testBinaryPath)
|
||||||
|
cmd := exec.Command("go", "build", "-tags=json", "-o="+testBinaryPath, GetSourcePath())
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunV2Ray(configFile string) *exec.Cmd {
|
func RunV2Ray(configFile string) *exec.Cmd {
|
||||||
binaryPath := GetTestBinaryPath()
|
GenTestBinaryPath()
|
||||||
proc := exec.Command(binaryPath, "-config", configFile)
|
proc := exec.Command(testBinaryPath, "-config", configFile)
|
||||||
proc.Stderr = os.Stderr
|
proc.Stderr = os.Stderr
|
||||||
proc.Stdout = os.Stdout
|
proc.Stdout = os.Stdout
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -9,11 +10,6 @@ import (
|
|||||||
"v2ray.com/core/testing/assert"
|
"v2ray.com/core/testing/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cleanBinPath() {
|
|
||||||
os.RemoveAll(binPath)
|
|
||||||
os.Mkdir(binPath, os.ModeDir|0777)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fileExists(file string) bool {
|
func fileExists(file string) bool {
|
||||||
_, err := os.Stat(file)
|
_, err := os.Stat(file)
|
||||||
return err == nil
|
return err == nil
|
||||||
@ -32,8 +28,10 @@ func allFilesExists(files ...string) bool {
|
|||||||
|
|
||||||
func TestBuildMacOS(t *testing.T) {
|
func TestBuildMacOS(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
|
tmpPath, err := ioutil.TempDir("", "v2ray")
|
||||||
cleanBinPath()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
|
binPath = tmpPath
|
||||||
|
|
||||||
build("macos", "amd64", true, "test", "metadata.txt")
|
build("macos", "amd64", true, "test", "metadata.txt")
|
||||||
assert.Bool(allFilesExists(
|
assert.Bool(allFilesExists(
|
||||||
|
Loading…
Reference in New Issue
Block a user