destination_test.go 880 B

12345678910111213141516171819202122232425262728
  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. }