commands_test.go 893 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package encoding_test
  2. import (
  3. "testing"
  4. "v2ray.com/core/common/buf"
  5. "v2ray.com/core/common/protocol"
  6. "v2ray.com/core/common/uuid"
  7. . "v2ray.com/core/proxy/vmess/encoding"
  8. . "v2ray.com/ext/assert"
  9. )
  10. func TestSwitchAccount(t *testing.T) {
  11. assert := With(t)
  12. sa := &protocol.CommandSwitchAccount{
  13. Port: 1234,
  14. ID: uuid.New(),
  15. AlterIds: 1024,
  16. Level: 128,
  17. ValidMin: 16,
  18. }
  19. buffer := buf.New()
  20. err := MarshalCommand(sa, buffer)
  21. assert(err, IsNil)
  22. cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
  23. assert(err, IsNil)
  24. sa2, ok := cmd.(*protocol.CommandSwitchAccount)
  25. assert(ok, IsTrue)
  26. assert(sa.Host, IsNil)
  27. assert(sa2.Host, IsNil)
  28. assert(sa.Port, Equals, sa2.Port)
  29. assert(sa.ID.String(), Equals, sa2.ID.String())
  30. assert(sa.AlterIds, Equals, sa2.AlterIds)
  31. assert(byte(sa.Level), Equals, byte(sa2.Level))
  32. assert(sa.ValidMin, Equals, sa2.ValidMin)
  33. }