mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-23 18:16:50 +08:00
v1.0.0
This commit is contained in:
65
common/platform/platform_test.go
Normal file
65
common/platform/platform_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package platform_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
. "github.com/xtls/xray-core/v1/common/platform"
|
||||
)
|
||||
|
||||
func TestNormalizeEnvName(t *testing.T) {
|
||||
cases := []struct {
|
||||
input string
|
||||
output string
|
||||
}{
|
||||
{
|
||||
input: "a",
|
||||
output: "A",
|
||||
},
|
||||
{
|
||||
input: "a.a",
|
||||
output: "A_A",
|
||||
},
|
||||
{
|
||||
input: "A.A.B",
|
||||
output: "A_A_B",
|
||||
},
|
||||
}
|
||||
for _, test := range cases {
|
||||
if v := NormalizeEnvName(test.input); v != test.output {
|
||||
t.Error("unexpected output: ", v, " want ", test.output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvFlag(t *testing.T) {
|
||||
if v := (EnvFlag{
|
||||
Name: "xxxxx.y",
|
||||
}.GetValueAsInt(10)); v != 10 {
|
||||
t.Error("env value: ", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAssetLocation(t *testing.T) {
|
||||
exec, err := os.Executable()
|
||||
common.Must(err)
|
||||
|
||||
loc := GetAssetLocation("t")
|
||||
if filepath.Dir(loc) != filepath.Dir(exec) {
|
||||
t.Error("asset dir: ", loc, " not in ", exec)
|
||||
}
|
||||
|
||||
os.Setenv("xray.location.asset", "/xray")
|
||||
if runtime.GOOS == "windows" {
|
||||
if v := GetAssetLocation("t"); v != "\\xray\\t" {
|
||||
t.Error("asset loc: ", v)
|
||||
}
|
||||
} else {
|
||||
if v := GetAssetLocation("t"); v != "/xray/t" {
|
||||
t.Error("asset loc: ", v)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user