accounts_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package command_test
  2. import (
  3. "bytes"
  4. "testing"
  5. "time"
  6. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  7. "github.com/v2ray/v2ray-core/common/uuid"
  8. . "github.com/v2ray/v2ray-core/proxy/vmess/command"
  9. v2testing "github.com/v2ray/v2ray-core/testing"
  10. "github.com/v2ray/v2ray-core/testing/assert"
  11. )
  12. func TestSwitchAccount(t *testing.T) {
  13. v2testing.Current(t)
  14. sa := &SwitchAccount{
  15. Port: 1234,
  16. ID: uuid.New(),
  17. AlterIds: 1024,
  18. ValidUntil: time.Now(),
  19. }
  20. cmd, err := CreateResponseCommand(1)
  21. assert.Error(err).IsNil()
  22. buffer := bytes.NewBuffer(make([]byte, 0, 1024))
  23. nBytes, err := sa.Marshal(buffer)
  24. assert.Error(err).IsNil()
  25. assert.Int(nBytes).Equals(buffer.Len())
  26. cmd.Unmarshal(buffer.Bytes())
  27. sa2, ok := cmd.(*SwitchAccount)
  28. assert.Bool(ok).IsTrue()
  29. netassert.Port(sa.Port).Equals(sa2.Port)
  30. assert.String(sa.ID).Equals(sa2.ID.String())
  31. assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
  32. assert.Int64(sa.ValidUntil.Unix()).Equals(sa2.ValidUntil.Unix())
  33. }