go_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "runtime"
  9. "strings"
  10. "testing"
  11. "time"
  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. target := filepath.Join(gopath, "src", "v2ray_test")
  18. fmt.Println(target)
  19. goOS := parseOS(runtime.GOOS)
  20. goArch := parseArch(runtime.GOARCH)
  21. err := buildV2Ray(target, "v1.0", goOS, goArch)
  22. assert.Error(err).IsNil()
  23. outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
  24. errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
  25. configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "release", "config", "vpoint_socks_vmess.json")
  26. cmd := exec.Command(target, "--config="+configFile)
  27. cmd.Stdout = outBuffer
  28. cmd.Stderr = errBuffer
  29. cmd.Start()
  30. <-time.After(1 * time.Second)
  31. cmd.Process.Kill()
  32. outStr := string(outBuffer.Bytes())
  33. errStr := string(errBuffer.Bytes())
  34. assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
  35. assert.Int(len(errStr)).Equals(0)
  36. os.Remove(target)
  37. }