1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-05 00:47:51 -05:00
v2fly/proxy/vmess/command/accounts_test.go

41 lines
1.0 KiB
Go
Raw Normal View History

2015-12-12 07:11:49 -05:00
package command_test
import (
"bytes"
"testing"
"time"
2016-01-18 19:21:07 -05:00
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
2015-12-12 07:11:49 -05: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-18 19:21:07 -05:00
Port: 1234,
2015-12-12 07:11:49 -05:00
ID: uuid.New(),
2016-01-18 19:21:07 -05:00
AlterIds: 1024,
2015-12-12 07:11:49 -05:00
ValidUntil: time.Now(),
}
cmd, err := CreateResponseCommand(1)
assert.Error(err).IsNil()
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
nBytes, err := sa.Marshal(buffer)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(buffer.Len())
cmd.Unmarshal(buffer.Bytes())
sa2, ok := cmd.(*SwitchAccount)
assert.Bool(ok).IsTrue()
2016-01-18 19:21:07 -05:00
netassert.Port(sa.Port).Equals(sa2.Port)
2015-12-12 07:11:49 -05:00
assert.String(sa.ID).Equals(sa2.ID.String())
2016-01-18 19:21:07 -05:00
assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
2015-12-12 07:11:49 -05:00
assert.Int64(sa.ValidUntil.Unix()).Equals(sa2.ValidUntil.Unix())
}