commands_test.go 1.0 KB

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