1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-07 05:44:28 -04:00
v2fly/common/platform/platform_test.go

75 lines
1.3 KiB
Go
Raw Normal View History

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"
. "v2ray.com/core/common/platform"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2017-05-25 19:11:38 -04:00
)
func TestNormalizeEnvName(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-05-25 19:11:38 -04: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 10:15:35 -04:00
assert(NormalizeEnvName(test.input), Equals, test.output)
2017-05-25 19:11:38 -04:00
}
}
func TestEnvFlag(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-05-25 19:11:38 -04:00
2017-10-24 10:15:35 -04:00
assert(EnvFlag{
2017-05-25 19:11:38 -04:00
Name: "xxxxx.y",
2017-10-24 10:15:35 -04:00
}.GetValueAsInt(10), Equals, 10)
2017-05-25 19:11:38 -04:00
}
2017-11-06 06:23:21 -05: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-13 23:57:26 -04:00
if runtime.GOOS == "windows" {
assert(GetAssetLocation("t"), Equals, "\\v2ray\\t")
} else {
assert(GetAssetLocation("t"), Equals, "/v2ray/t")
}
2017-11-06 06:23:21 -05:00
}
2017-12-17 18:07:50 -05: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")
}