mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-01 08:17:25 +00:00
simplify testing
This commit is contained in:
@@ -3,7 +3,6 @@ package inbound
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
"github.com/v2ray/v2ray-core/common/protocol"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
)
|
||||
|
||||
func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand {
|
||||
@@ -23,7 +22,7 @@ func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader
|
||||
return &protocol.CommandSwitchAccount{
|
||||
Port: inboundHandler.Port(),
|
||||
ID: user.ID.UUID(),
|
||||
AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
|
||||
AlterIds: uint16(len(user.AlterIDs)),
|
||||
Level: user.Level,
|
||||
ValidMin: byte(availableMin),
|
||||
}
|
||||
|
||||
@@ -9,12 +9,11 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
. "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestAuthenticate(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewBuffer().Clear()
|
||||
buffer.AppendBytes(1, 2, 3, 4)
|
||||
@@ -27,7 +26,7 @@ func TestAuthenticate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSingleIO(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
content := bytes.NewBuffer(make([]byte, 0, 1024*1024))
|
||||
|
||||
@@ -42,7 +41,7 @@ func TestSingleIO(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLargeIO(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
content := make([]byte, 1024*1024)
|
||||
rand.Read(content)
|
||||
|
||||
@@ -35,5 +35,5 @@ func Authenticate(buffer *alloc.Buffer) {
|
||||
buffer.SliceBack(4)
|
||||
fnvHash.Sum(buffer.Value[:0])
|
||||
|
||||
buffer.Prepend(serial.Uint16Literal(uint16(buffer.Len())).Bytes())
|
||||
buffer.Prepend(serial.Uint16ToBytes(uint16(buffer.Len())))
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
|
||||
primary := protocol.NewID(cmd.ID)
|
||||
alters := protocol.NewAlterIDs(primary, cmd.AlterIds.Value())
|
||||
alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
|
||||
user := protocol.NewUser(primary, alters, cmd.Level, "")
|
||||
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
|
||||
this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
"testing"
|
||||
|
||||
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestConfigTargetParsing(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawJson := `{
|
||||
"address": "127.0.0.1",
|
||||
@@ -29,7 +28,7 @@ func TestConfigTargetParsing(t *testing.T) {
|
||||
receiver := new(Receiver)
|
||||
err := json.Unmarshal([]byte(rawJson), &receiver)
|
||||
assert.Error(err).IsNil()
|
||||
assert.String(receiver.Destination).Equals("tcp:127.0.0.1:80")
|
||||
assert.Destination(receiver.Destination).EqualsString("tcp:127.0.0.1:80")
|
||||
assert.Int(len(receiver.Accounts)).Equals(1)
|
||||
assert.String(receiver.Accounts[0].ID).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019")
|
||||
assert.String(receiver.Accounts[0].ID.String()).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019")
|
||||
}
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/protocol"
|
||||
"github.com/v2ray/v2ray-core/common/uuid"
|
||||
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestReceiverUser(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
id := protocol.NewID(uuid.New())
|
||||
alters := protocol.NewAlterIDs(id, 100)
|
||||
|
||||
@@ -17,12 +17,11 @@ import (
|
||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||
"github.com/v2ray/v2ray-core/shell/point"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestVMessInAndOut(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
id, err := uuid.ParseString("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
Reference in New Issue
Block a user