build_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "github.com/v2ray/v2ray-core/testing/assert"
  8. )
  9. func cleanBinPath() {
  10. os.RemoveAll(binPath)
  11. os.Mkdir(binPath, os.ModeDir|0777)
  12. }
  13. func fileExists(file string) bool {
  14. _, err := os.Stat(file)
  15. return err == nil
  16. }
  17. func allFilesExists(files ...string) bool {
  18. for _, file := range files {
  19. fullPath := filepath.Join(binPath, file)
  20. if !fileExists(fullPath) {
  21. fmt.Println(fullPath + " doesn't exist.")
  22. return false
  23. }
  24. }
  25. return true
  26. }
  27. func TestBuildMacOS(t *testing.T) {
  28. assert := assert.On(t)
  29. binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
  30. cleanBinPath()
  31. build("macos", "amd64", true, "test", "metadata.txt")
  32. assert.Bool(allFilesExists(
  33. "v2ray-macos.zip",
  34. "v2ray-test-macos",
  35. filepath.Join("v2ray-test-macos", "config.json"),
  36. filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()
  37. build("windows", "amd64", true, "test", "metadata.txt")
  38. assert.Bool(allFilesExists(
  39. "v2ray-windows-64.zip",
  40. "v2ray-test-windows-64",
  41. filepath.Join("v2ray-test-windows-64", "config.json"),
  42. filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()
  43. build("linux", "amd64", true, "test", "metadata.txt")
  44. assert.Bool(allFilesExists(
  45. "v2ray-linux-64.zip",
  46. "v2ray-test-linux-64",
  47. filepath.Join("v2ray-test-linux-64", "vpoint_socks_vmess.json"),
  48. filepath.Join("v2ray-test-linux-64", "vpoint_vmess_freedom.json"),
  49. filepath.Join("v2ray-test-linux-64", "v2ray"))).IsTrue()
  50. }