github.com/moqsien/xraycore@v1.8.5/common/platform/platform_test.go (about) 1 package platform_test 2 3 import ( 4 "os" 5 "path/filepath" 6 "runtime" 7 "testing" 8 9 "github.com/moqsien/xraycore/common" 10 . "github.com/moqsien/xraycore/common/platform" 11 ) 12 13 func TestNormalizeEnvName(t *testing.T) { 14 cases := []struct { 15 input string 16 output string 17 }{ 18 { 19 input: "a", 20 output: "A", 21 }, 22 { 23 input: "a.a", 24 output: "A_A", 25 }, 26 { 27 input: "A.A.B", 28 output: "A_A_B", 29 }, 30 } 31 for _, test := range cases { 32 if v := NormalizeEnvName(test.input); v != test.output { 33 t.Error("unexpected output: ", v, " want ", test.output) 34 } 35 } 36 } 37 38 func TestEnvFlag(t *testing.T) { 39 if v := (EnvFlag{ 40 Name: "xxxxx.y", 41 }.GetValueAsInt(10)); v != 10 { 42 t.Error("env value: ", v) 43 } 44 } 45 46 func TestGetAssetLocation(t *testing.T) { 47 exec, err := os.Executable() 48 common.Must(err) 49 50 loc := GetAssetLocation("t") 51 if filepath.Dir(loc) != filepath.Dir(exec) { 52 t.Error("asset dir: ", loc, " not in ", exec) 53 } 54 55 os.Setenv("xray.location.asset", "/xray") 56 if runtime.GOOS == "windows" { 57 if v := GetAssetLocation("t"); v != "\\xray\\t" { 58 t.Error("asset loc: ", v) 59 } 60 } else { 61 if v := GetAssetLocation("t"); v != "/xray/t" { 62 t.Error("asset loc: ", v) 63 } 64 } 65 }