accounts_test.go 927 B

12345678910111213141516171819202122232425262728293031323334353637
  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. ValidSec: 8080,
  18. }
  19. cmd, err := CreateResponseCommand(1)
  20. assert.Error(err).IsNil()
  21. buffer := bytes.NewBuffer(make([]byte, 0, 1024))
  22. sa.Marshal(buffer)
  23. cmd.Unmarshal(buffer.Bytes())
  24. sa2, ok := cmd.(*SwitchAccount)
  25. assert.Bool(ok).IsTrue()
  26. netassert.Port(sa.Port).Equals(sa2.Port)
  27. assert.String(sa.ID).Equals(sa2.ID.String())
  28. assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
  29. assert.Uint16(sa.ValidSec.Value()).Equals(sa2.ValidSec.Value())
  30. }