1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-15 16:38:16 -04:00
v2fly/common/protocol/raw/commands_test.go

41 lines
1.0 KiB
Go
Raw Normal View History

2016-02-26 18:05:53 -05:00
package raw_test
import (
"testing"
2016-02-27 11:28:21 -05:00
"github.com/v2ray/v2ray-core/common/alloc"
2016-02-26 18:05:53 -05:00
"github.com/v2ray/v2ray-core/common/protocol"
. "github.com/v2ray/v2ray-core/common/protocol/raw"
"github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestSwitchAccount(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-26 18:05:53 -05:00
sa := &protocol.CommandSwitchAccount{
Port: 1234,
ID: uuid.New(),
AlterIds: 1024,
Level: 128,
ValidMin: 16,
}
2016-02-27 11:28:21 -05:00
buffer := alloc.NewBuffer().Clear()
2016-02-26 18:05:53 -05:00
err := MarshalCommand(sa, buffer)
assert.Error(err).IsNil()
2016-02-27 11:28:21 -05:00
cmd, err := UnmarshalCommand(1, buffer.Value[2:])
2016-02-26 18:05:53 -05:00
assert.Error(err).IsNil()
sa2, ok := cmd.(*protocol.CommandSwitchAccount)
assert.Bool(ok).IsTrue()
assert.Pointer(sa.Host).IsNil()
assert.Pointer(sa2.Host).IsNil()
2016-05-24 09:29:08 -04:00
assert.Port(sa.Port).Equals(sa2.Port)
2016-05-24 15:55:46 -04:00
assert.String(sa.ID.String()).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds).Equals(sa2.AlterIds)
2016-02-26 18:05:53 -05:00
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}