1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/tools/build/go_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2015-10-17 18:50:51 -04:00
package main
import (
"bytes"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
2016-08-20 14:55:45 -04:00
"v2ray.com/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"
}
2017-02-23 13:46:58 -05:00
err := buildV2Ray(target, "v1.0", goOS, goArch, "")
2015-10-17 18:50:51 -04:00
assert.Error(err).IsNil()
outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
2016-07-27 15:58:54 -04:00
configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "tools", "release", "config", "vpoint_socks_vmess.json")
2015-10-17 18:50:51 -04:00
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)
}