net_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package ice
  4. import (
  5. "net"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestIsSupportedIPv6(t *testing.T) {
  10. if isSupportedIPv6(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}) {
  11. t.Errorf("isSupportedIPv6 return true with IPv4-compatible IPv6 address")
  12. }
  13. if isSupportedIPv6(net.ParseIP("fec0::2333")) {
  14. t.Errorf("isSupportedIPv6 return true with IPv6 site-local unicast address")
  15. }
  16. if isSupportedIPv6(net.ParseIP("fe80::2333")) {
  17. t.Errorf("isSupportedIPv6 return true with IPv6 link-local address")
  18. }
  19. if isSupportedIPv6(net.ParseIP("ff02::2333")) {
  20. t.Errorf("isSupportedIPv6 return true with IPv6 link-local multicast address")
  21. }
  22. if !isSupportedIPv6(net.ParseIP("2001::1")) {
  23. t.Errorf("isSupportedIPv6 return false with IPv6 global unicast address")
  24. }
  25. }
  26. func TestCreateAddr(t *testing.T) {
  27. ipv4 := net.IP{127, 0, 0, 1}
  28. ipv6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
  29. port := 9000
  30. assert.Equal(t, &net.UDPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeUDP4, ipv4, port))
  31. assert.Equal(t, &net.UDPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeUDP6, ipv6, port))
  32. assert.Equal(t, &net.TCPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeTCP4, ipv4, port))
  33. assert.Equal(t, &net.TCPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeTCP6, ipv6, port))
  34. }