destination_test.go 1.9 KB

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