2016-07-23 11:17:51 +00:00
|
|
|
package encoding_test
|
2016-02-26 23:05:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-12-09 10:35:27 +00:00
|
|
|
"v2ray.com/core/common/buf"
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/common/protocol"
|
|
|
|
"v2ray.com/core/common/uuid"
|
|
|
|
. "v2ray.com/core/proxy/vmess/encoding"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-02-26 23:05:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSwitchAccount(t *testing.T) {
|
2016-05-24 19:55:46 +00:00
|
|
|
assert := assert.On(t)
|
2016-02-26 23:05:53 +00:00
|
|
|
|
|
|
|
sa := &protocol.CommandSwitchAccount{
|
|
|
|
Port: 1234,
|
|
|
|
ID: uuid.New(),
|
|
|
|
AlterIds: 1024,
|
|
|
|
Level: 128,
|
|
|
|
ValidMin: 16,
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:08:25 +00:00
|
|
|
buffer := buf.New()
|
2016-02-26 23:05:53 +00:00
|
|
|
err := MarshalCommand(sa, buffer)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
2016-12-05 20:33:24 +00:00
|
|
|
cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
|
2016-02-26 23:05:53 +00: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 13:29:08 +00:00
|
|
|
assert.Port(sa.Port).Equals(sa2.Port)
|
2016-05-24 19:55:46 +00:00
|
|
|
assert.String(sa.ID.String()).Equals(sa2.ID.String())
|
|
|
|
assert.Uint16(sa.AlterIds).Equals(sa2.AlterIds)
|
2016-02-26 23:05:53 +00:00
|
|
|
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
|
|
|
|
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
|
|
|
|
}
|