platform_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package platform_test
  2. import (
  3. "os"
  4. "path/filepath"
  5. "runtime"
  6. "testing"
  7. "v2ray.com/core/common"
  8. . "v2ray.com/core/common/platform"
  9. . "v2ray.com/ext/assert"
  10. )
  11. func TestNormalizeEnvName(t *testing.T) {
  12. assert := With(t)
  13. cases := []struct {
  14. input string
  15. output string
  16. }{
  17. {
  18. input: "a",
  19. output: "A",
  20. },
  21. {
  22. input: "a.a",
  23. output: "A_A",
  24. },
  25. {
  26. input: "A.A.B",
  27. output: "A_A_B",
  28. },
  29. }
  30. for _, test := range cases {
  31. assert(NormalizeEnvName(test.input), Equals, test.output)
  32. }
  33. }
  34. func TestEnvFlag(t *testing.T) {
  35. assert := With(t)
  36. assert(EnvFlag{
  37. Name: "xxxxx.y",
  38. }.GetValueAsInt(10), Equals, 10)
  39. }
  40. func TestGetAssetLocation(t *testing.T) {
  41. assert := With(t)
  42. exec, err := os.Executable()
  43. common.Must(err)
  44. loc := GetAssetLocation("t")
  45. assert(filepath.Dir(loc), Equals, filepath.Dir(exec))
  46. os.Setenv("v2ray.location.asset", "/v2ray")
  47. if runtime.GOOS == "windows" {
  48. assert(GetAssetLocation("t"), Equals, "\\v2ray\\t")
  49. } else {
  50. assert(GetAssetLocation("t"), Equals, "/v2ray/t")
  51. }
  52. }
  53. func TestGetPluginLocation(t *testing.T) {
  54. assert := With(t)
  55. exec, err := os.Executable()
  56. common.Must(err)
  57. loc := GetPluginDirectory()
  58. assert(loc, Equals, filepath.Join(filepath.Dir(exec), "plugins"))
  59. os.Setenv("V2RAY_LOCATION_PLUGIN", "/v2ray")
  60. assert(GetPluginDirectory(), Equals, "/v2ray")
  61. }