go_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "bytes"
  4. "os"
  5. "os/exec"
  6. "path/filepath"
  7. "runtime"
  8. "strings"
  9. "testing"
  10. "time"
  11. "v2ray.com/core/testing/assert"
  12. )
  13. func TestBuildAndRun(t *testing.T) {
  14. assert := assert.On(t)
  15. gopath := os.Getenv("GOPATH")
  16. goOS := parseOS(runtime.GOOS)
  17. goArch := parseArch(runtime.GOARCH)
  18. target := filepath.Join(gopath, "src", "v2ray_test")
  19. if goOS == Windows {
  20. target += ".exe"
  21. }
  22. err := buildV2Ray(target, "v1.0", goOS, goArch, "")
  23. assert.Error(err).IsNil()
  24. outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
  25. errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
  26. configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "tools", "release", "config", "vpoint_socks_vmess.json")
  27. cmd := exec.Command(target, "--config="+configFile)
  28. cmd.Stdout = outBuffer
  29. cmd.Stderr = errBuffer
  30. cmd.Start()
  31. time.Sleep(1 * time.Second)
  32. cmd.Process.Kill()
  33. outStr := string(outBuffer.Bytes())
  34. errStr := string(errBuffer.Bytes())
  35. assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
  36. assert.String(errStr).Equals("")
  37. os.Remove(target)
  38. }