destination_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package net_test
  2. import (
  3. "testing"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. v2testing "github.com/v2ray/v2ray-core/testing"
  6. "github.com/v2ray/v2ray-core/testing/assert"
  7. )
  8. func TestTCPDestination(t *testing.T) {
  9. v2testing.Current(t)
  10. dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  11. assert.Destination(dest).IsTCP()
  12. assert.Destination(dest).IsNotUDP()
  13. assert.String(dest).Equals("tcp:1.2.3.4:80")
  14. }
  15. func TestUDPDestination(t *testing.T) {
  16. v2testing.Current(t)
  17. dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
  18. assert.Destination(dest).IsNotTCP()
  19. assert.Destination(dest).IsUDP()
  20. assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53")
  21. }
  22. func TestTCPDestinationEquals(t *testing.T) {
  23. v2testing.Current(t)
  24. dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  25. assert.Bool(dest.Equals(nil)).IsFalse()
  26. dest2 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  27. assert.Bool(dest.Equals(dest2)).IsTrue()
  28. dest3 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  29. assert.Bool(dest.Equals(dest3)).IsFalse()
  30. dest4 := v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)
  31. assert.Bool(dest.Equals(dest4)).IsFalse()
  32. }
  33. func TestUDPDestinationEquals(t *testing.T) {
  34. v2testing.Current(t)
  35. dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  36. assert.Bool(dest.Equals(nil)).IsFalse()
  37. dest2 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  38. assert.Bool(dest.Equals(dest2)).IsTrue()
  39. dest3 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
  40. assert.Bool(dest.Equals(dest3)).IsFalse()
  41. dest4 := v2net.UDPDestination(v2net.DomainAddress("v2ray.com"), 80)
  42. assert.Bool(dest.Equals(dest4)).IsFalse()
  43. }