simplify testing

This commit is contained in:
v2ray
2016-05-24 21:55:46 +02:00
parent 3582b9d869
commit fc63f0432c
99 changed files with 726 additions and 817 deletions
+1 -2
View File
@@ -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),
}
+3 -4
View File
@@ -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)
+1 -1
View File
@@ -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())))
}
+1 -1
View File
@@ -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)
+3 -4
View File
@@ -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")
}
+1 -2
View File
@@ -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)
+1 -2
View File
@@ -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()