commands_test.go 1.1 KB

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