platform_test.go 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }