Darien Raymond 7 лет назад
Родитель
Сommit
a0b2c285b2
3 измененных файлов с 57 добавлено и 0 удалено
  1. 13 0
      common/platform/platform_test.go
  2. 10 0
      common/protocol/id_test.go
  3. 34 0
      common/protocol/server_spec_test.go

+ 13 - 0
common/platform/platform_test.go

@@ -54,3 +54,16 @@ func TestGetAssetLocation(t *testing.T) {
 	os.Setenv("v2ray.location.asset", "/v2ray")
 	assert(GetAssetLocation("t"), Equals, "/v2ray/t")
 }
+
+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")
+}

+ 10 - 0
common/protocol/id_test.go

@@ -15,3 +15,13 @@ func TestCmdKey(t *testing.T) {
 	id := NewID(uuid.New())
 	assert(predicate.BytesAll(id.CmdKey(), 0), IsFalse)
 }
+
+func TestIdEquals(t *testing.T) {
+	assert := With(t)
+
+	id1 := NewID(uuid.New())
+	id2 := NewID(id1.UUID())
+
+	assert(id1.Equals(id2), IsTrue)
+	assert(id1.String(), Equals, id2.String())
+}

+ 34 - 0
common/protocol/server_spec_test.go

@@ -4,7 +4,11 @@ import (
 	"testing"
 	"time"
 
+	"v2ray.com/core/common/net"
 	. "v2ray.com/core/common/protocol"
+	"v2ray.com/core/common/serial"
+	"v2ray.com/core/common/uuid"
+	"v2ray.com/core/proxy/vmess"
 	. "v2ray.com/ext/assert"
 )
 
@@ -29,3 +33,33 @@ func TestTimeoutValidStrategy(t *testing.T) {
 	strategy.Invalidate()
 	assert(strategy.IsValid(), IsFalse)
 }
+
+func TestUserInServerSpec(t *testing.T) {
+	assert := With(t)
+
+	uuid1 := uuid.New()
+	uuid2 := uuid.New()
+
+	spec := NewServerSpec(net.Destination{}, AlwaysValid(), &User{
+		Email:   "test1@v2ray.com",
+		Account: serial.ToTypedMessage(&vmess.Account{Id: uuid1.String()}),
+	})
+	assert(spec.HasUser(&User{
+		Email:   "test1@v2ray.com",
+		Account: serial.ToTypedMessage(&vmess.Account{Id: uuid2.String()}),
+	}), IsFalse)
+
+	spec.AddUser(&User{Email: "test2@v2ray.com"})
+	assert(spec.HasUser(&User{
+		Email:   "test1@v2ray.com",
+		Account: serial.ToTypedMessage(&vmess.Account{Id: uuid1.String()}),
+	}), IsTrue)
+}
+
+func TestPickUser(t *testing.T) {
+	assert := With(t)
+
+	spec := NewServerSpec(net.Destination{}, AlwaysValid(), &User{Email: "test1@v2ray.com"}, &User{Email: "test2@v2ray.com"}, &User{Email: "test3@v2ray.com"})
+	user := spec.PickUser()
+	assert(user.Email, HasSuffix, "@v2ray.com")
+}