2015-10-17 18:50:51 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-10-17 18:50:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildAndRun(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2015-10-17 18:50:51 -04:00
|
|
|
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
goOS := parseOS(runtime.GOOS)
|
|
|
|
goArch := parseArch(runtime.GOARCH)
|
2016-04-18 12:44:10 -04:00
|
|
|
target := filepath.Join(gopath, "src", "v2ray_test")
|
|
|
|
if goOS == Windows {
|
|
|
|
target += ".exe"
|
|
|
|
}
|
2015-10-17 18:50:51 -04:00
|
|
|
err := buildV2Ray(target, "v1.0", goOS, goArch)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
|
|
|
outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
|
|
|
|
errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
|
|
|
|
configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "release", "config", "vpoint_socks_vmess.json")
|
|
|
|
cmd := exec.Command(target, "--config="+configFile)
|
|
|
|
cmd.Stdout = outBuffer
|
|
|
|
cmd.Stderr = errBuffer
|
|
|
|
cmd.Start()
|
|
|
|
|
|
|
|
<-time.After(1 * time.Second)
|
|
|
|
cmd.Process.Kill()
|
|
|
|
|
|
|
|
outStr := string(outBuffer.Bytes())
|
|
|
|
errStr := string(errBuffer.Bytes())
|
|
|
|
|
|
|
|
assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
|
2016-05-24 15:55:46 -04:00
|
|
|
assert.String(errStr).Equals("")
|
2015-10-17 18:50:51 -04:00
|
|
|
|
|
|
|
os.Remove(target)
|
|
|
|
}
|