accounts_test.go 819 B

1234567891011121314151617181920212223242526272829303132333435
  1. package command_test
  2. import (
  3. "bytes"
  4. "testing"
  5. "time"
  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. ID: uuid.New(),
  15. ValidUntil: time.Now(),
  16. }
  17. cmd, err := CreateResponseCommand(1)
  18. assert.Error(err).IsNil()
  19. buffer := bytes.NewBuffer(make([]byte, 0, 1024))
  20. nBytes, err := sa.Marshal(buffer)
  21. assert.Error(err).IsNil()
  22. assert.Int(nBytes).Equals(buffer.Len())
  23. cmd.Unmarshal(buffer.Bytes())
  24. sa2, ok := cmd.(*SwitchAccount)
  25. assert.Bool(ok).IsTrue()
  26. assert.String(sa.ID).Equals(sa2.ID.String())
  27. assert.Int64(sa.ValidUntil.Unix()).Equals(sa2.ValidUntil.Unix())
  28. }