2017-05-25 19:11:38 -04:00
|
|
|
package platform_test
|
|
|
|
|
|
|
|
import (
|
2017-11-06 06:23:21 -05:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-04-13 23:57:26 -04:00
|
|
|
"runtime"
|
2017-05-25 19:11:38 -04:00
|
|
|
"testing"
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
|
|
. "github.com/v2fly/v2ray-core/v4/common/platform"
|
2017-05-25 19:11:38 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2019-02-09 09:46:48 -05:00
|
|
|
if v := NormalizeEnvName(test.input); v != test.output {
|
|
|
|
t.Error("unexpected output: ", v, " want ", test.output)
|
|
|
|
}
|
2017-05-25 19:11:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvFlag(t *testing.T) {
|
2019-02-10 09:26:43 -05:00
|
|
|
if v := (EnvFlag{
|
2017-05-25 19:11:38 -04:00
|
|
|
Name: "xxxxx.y",
|
2019-02-10 09:26:43 -05:00
|
|
|
}.GetValueAsInt(10)); v != 10 {
|
2019-02-09 09:46:48 -05:00
|
|
|
t.Error("env value: ", v)
|
|
|
|
}
|
2017-05-25 19:11:38 -04:00
|
|
|
}
|
2017-11-06 06:23:21 -05:00
|
|
|
|
|
|
|
func TestGetAssetLocation(t *testing.T) {
|
|
|
|
exec, err := os.Executable()
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2017-11-06 06:23:21 -05:00
|
|
|
|
|
|
|
loc := GetAssetLocation("t")
|
2019-02-09 09:46:48 -05:00
|
|
|
if filepath.Dir(loc) != filepath.Dir(exec) {
|
|
|
|
t.Error("asset dir: ", loc, " not in ", exec)
|
|
|
|
}
|
2017-11-06 06:23:21 -05:00
|
|
|
|
|
|
|
os.Setenv("v2ray.location.asset", "/v2ray")
|
2018-04-13 23:57:26 -04:00
|
|
|
if runtime.GOOS == "windows" {
|
2019-02-09 09:46:48 -05:00
|
|
|
if v := GetAssetLocation("t"); v != "\\v2ray\\t" {
|
|
|
|
t.Error("asset loc: ", v)
|
|
|
|
}
|
2018-04-13 23:57:26 -04:00
|
|
|
} else {
|
2019-02-09 09:46:48 -05:00
|
|
|
if v := GetAssetLocation("t"); v != "/v2ray/t" {
|
|
|
|
t.Error("asset loc: ", v)
|
|
|
|
}
|
2018-04-13 23:57:26 -04:00
|
|
|
}
|
2017-11-06 06:23:21 -05:00
|
|
|
}
|