go_test.go 1.1 KB

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