build_test.go 1.4 KB

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