accounts_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package command_test
  2. import (
  3. "bytes"
  4. "testing"
  5. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  6. "github.com/v2ray/v2ray-core/common/uuid"
  7. . "github.com/v2ray/v2ray-core/proxy/vmess/command"
  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 := &SwitchAccount{
  14. Port: 1234,
  15. ID: uuid.New(),
  16. AlterIds: 1024,
  17. Level: 128,
  18. ValidMin: 16,
  19. }
  20. cmd, err := CreateResponseCommand(1)
  21. assert.Error(err).IsNil()
  22. buffer := bytes.NewBuffer(make([]byte, 0, 1024))
  23. sa.Marshal(buffer)
  24. cmd.Unmarshal(buffer.Bytes())
  25. sa2, ok := cmd.(*SwitchAccount)
  26. assert.Bool(ok).IsTrue()
  27. assert.Pointer(sa.Host).IsNil()
  28. assert.Pointer(sa2.Host).IsNil()
  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.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
  33. assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
  34. }