commands_test.go 811 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package encoding_test
  2. import (
  3. "testing"
  4. "github.com/google/go-cmp/cmp"
  5. "github.com/v2fly/v2ray-core/v4/common"
  6. "github.com/v2fly/v2ray-core/v4/common/buf"
  7. "github.com/v2fly/v2ray-core/v4/common/protocol"
  8. "github.com/v2fly/v2ray-core/v4/common/uuid"
  9. . "github.com/v2fly/v2ray-core/v4/proxy/vmess/encoding"
  10. )
  11. func TestSwitchAccount(t *testing.T) {
  12. sa := &protocol.CommandSwitchAccount{
  13. Port: 1234,
  14. ID: uuid.New(),
  15. AlterIds: 1024,
  16. Level: 128,
  17. ValidMin: 16,
  18. }
  19. buffer := buf.New()
  20. common.Must(MarshalCommand(sa, buffer))
  21. cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
  22. common.Must(err)
  23. sa2, ok := cmd.(*protocol.CommandSwitchAccount)
  24. if !ok {
  25. t.Fatal("failed to convert command to CommandSwitchAccount")
  26. }
  27. if r := cmp.Diff(sa2, sa); r != "" {
  28. t.Error(r)
  29. }
  30. }