platform_test.go 1.2 KB

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