commands_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package raw_test
  2. import (
  3. "testing"
  4. "github.com/v2ray/v2ray-core/common/alloc"
  5. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  6. "github.com/v2ray/v2ray-core/common/protocol"
  7. . "github.com/v2ray/v2ray-core/common/protocol/raw"
  8. "github.com/v2ray/v2ray-core/common/uuid"
  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 := &protocol.CommandSwitchAccount{
  15. Port: 1234,
  16. ID: uuid.New(),
  17. AlterIds: 1024,
  18. Level: 128,
  19. ValidMin: 16,
  20. }
  21. buffer := alloc.NewBuffer().Clear()
  22. err := MarshalCommand(sa, buffer)
  23. assert.Error(err).IsNil()
  24. cmd, err := UnmarshalCommand(1, buffer.Value[2:])
  25. assert.Error(err).IsNil()
  26. sa2, ok := cmd.(*protocol.CommandSwitchAccount)
  27. assert.Bool(ok).IsTrue()
  28. assert.Pointer(sa.Host).IsNil()
  29. assert.Pointer(sa2.Host).IsNil()
  30. netassert.Port(sa.Port).Equals(sa2.Port)
  31. assert.String(sa.ID).Equals(sa2.ID.String())
  32. assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
  33. assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
  34. assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
  35. }