platform_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package platform_test
  2. import (
  3. "os"
  4. "path/filepath"
  5. "runtime"
  6. "testing"
  7. "github.com/xtls/xray-core/common"
  8. . "github.com/xtls/xray-core/common/platform"
  9. )
  10. func TestNormalizeEnvName(t *testing.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. if v := NormalizeEnvName(test.input); v != test.output {
  30. t.Error("unexpected output: ", v, " want ", test.output)
  31. }
  32. }
  33. }
  34. func TestEnvFlag(t *testing.T) {
  35. if v := (EnvFlag{
  36. Name: "xxxxx.y",
  37. }.GetValueAsInt(10)); v != 10 {
  38. t.Error("env value: ", v)
  39. }
  40. }
  41. func TestGetAssetLocation(t *testing.T) {
  42. exec, err := os.Executable()
  43. common.Must(err)
  44. loc := GetAssetLocation("t")
  45. if filepath.Dir(loc) != filepath.Dir(exec) {
  46. t.Error("asset dir: ", loc, " not in ", exec)
  47. }
  48. os.Setenv("xray.location.asset", "/xray")
  49. if runtime.GOOS == "windows" {
  50. if v := GetAssetLocation("t"); v != "\\xray\\t" {
  51. t.Error("asset loc: ", v)
  52. }
  53. } else {
  54. if v := GetAssetLocation("t"); v != "/xray/t" {
  55. t.Error("asset loc: ", v)
  56. }
  57. }
  58. }