2017-05-25 23:11:38 +00:00
|
|
|
package platform_test
|
|
|
|
|
|
|
|
import (
|
2017-11-06 11:23:21 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-04-14 03:57:26 +00:00
|
|
|
"runtime"
|
2017-05-25 23:11:38 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "v2ray.com/core/common/platform"
|
2017-10-24 14:15:35 +00:00
|
|
|
. "v2ray.com/ext/assert"
|
2017-05-25 23:11:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalizeEnvName(t *testing.T) {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert := With(t)
|
2017-05-25 23:11:38 +00:00
|
|
|
|
|
|
|
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 {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(NormalizeEnvName(test.input), Equals, test.output)
|
2017-05-25 23:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvFlag(t *testing.T) {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert := With(t)
|
2017-05-25 23:11:38 +00:00
|
|
|
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(EnvFlag{
|
2017-05-25 23:11:38 +00:00
|
|
|
Name: "xxxxx.y",
|
2017-10-24 14:15:35 +00:00
|
|
|
}.GetValueAsInt(10), Equals, 10)
|
2017-05-25 23:11:38 +00:00
|
|
|
}
|
2017-11-06 11:23:21 +00:00
|
|
|
|
|
|
|
func TestGetAssetLocation(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
|
|
|
|
exec, err := os.Executable()
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
loc := GetAssetLocation("t")
|
|
|
|
assert(filepath.Dir(loc), Equals, filepath.Dir(exec))
|
|
|
|
|
|
|
|
os.Setenv("v2ray.location.asset", "/v2ray")
|
2018-04-14 03:57:26 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
assert(GetAssetLocation("t"), Equals, "\\v2ray\\t")
|
|
|
|
} else {
|
|
|
|
assert(GetAssetLocation("t"), Equals, "/v2ray/t")
|
|
|
|
}
|
2017-11-06 11:23:21 +00:00
|
|
|
}
|
2017-12-17 23:07:50 +00:00
|
|
|
|
|
|
|
func TestGetPluginLocation(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
|
|
|
|
exec, err := os.Executable()
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
loc := GetPluginDirectory()
|
|
|
|
assert(loc, Equals, filepath.Join(filepath.Dir(exec), "plugins"))
|
|
|
|
|
|
|
|
os.Setenv("V2RAY_LOCATION_PLUGIN", "/v2ray")
|
|
|
|
assert(GetPluginDirectory(), Equals, "/v2ray")
|
|
|
|
}
|