1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-05 01:38:24 -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"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
2015-12-02 11:27:55 -05:00
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
2015-10-17 18:50:51 -04:00
)
func TestBuildAndRun(t *testing.T) {
v2testing.Current(t)
2015-10-17 18:50:51 -04:00
gopath := os.Getenv("GOPATH")
target := filepath.Join(gopath, "src", "v2ray_test")
fmt.Println(target)
goOS := parseOS(runtime.GOOS)
goArch := parseArch(runtime.GOARCH)
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()
2015-12-03 16:41:06 -05:00
assert.StringLiteral(errStr).Equals("")
2015-10-17 18:50:51 -04:00
os.Remove(target)
}