v2ray-core/proxy/vmess/command/accounts_test.go

42 lines
1.0 KiB
Go
Raw Normal View History

2015-12-12 13:11:49 +01:00
package command_test
import (
"bytes"
"testing"
2016-01-19 01:21:07 +01:00
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
2015-12-12 13:11:49 +01:00
"github.com/v2ray/v2ray-core/common/uuid"
. "github.com/v2ray/v2ray-core/proxy/vmess/command"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestSwitchAccount(t *testing.T) {
v2testing.Current(t)
sa := &SwitchAccount{
2016-01-19 23:41:40 +01:00
Port: 1234,
ID: uuid.New(),
AlterIds: 1024,
Level: 128,
ValidMin: 16,
2015-12-12 13:11:49 +01:00
}
cmd, err := CreateResponseCommand(1)
assert.Error(err).IsNil()
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
2016-01-19 23:41:40 +01:00
sa.Marshal(buffer)
2015-12-12 13:11:49 +01:00
cmd.Unmarshal(buffer.Bytes())
sa2, ok := cmd.(*SwitchAccount)
assert.Bool(ok).IsTrue()
2016-01-21 16:29:18 +00:00
assert.Pointer(sa.Host).IsNil()
assert.Pointer(sa2.Host).IsNil()
2016-01-19 01:21:07 +01:00
netassert.Port(sa.Port).Equals(sa2.Port)
2015-12-12 13:11:49 +01:00
assert.String(sa.ID).Equals(sa2.ID.String())
2016-01-19 01:21:07 +01:00
assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
2015-12-12 13:11:49 +01:00
}