2017-05-25 19:11:38 -04:00
|
|
|
package platform_test
|
|
|
|
|
|
|
|
import (
|
2017-11-06 06:23:21 -05:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
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")
|
|
|
|
assert(GetAssetLocation("t"), Equals, "/v2ray/t")
|
|
|
|
}
|
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")
|
|
|
|
}
|