destination_test.go 1.8 KB

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