platform_test.go 1.3 KB

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