File: net_test.go

package info (click to toggle)
golang-github-pion-ice.v2 2.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 684 kB
  • sloc: makefile: 5
file content (41 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package ice

import (
	"net"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestIsSupportedIPv6(t *testing.T) {
	if isSupportedIPv6(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}) {
		t.Errorf("isSupportedIPv6 return true with IPv4-compatible IPv6 address")
	}

	if isSupportedIPv6(net.ParseIP("fec0::2333")) {
		t.Errorf("isSupportedIPv6 return true with IPv6 site-local unicast address")
	}

	if isSupportedIPv6(net.ParseIP("fe80::2333")) {
		t.Errorf("isSupportedIPv6 return true with IPv6 link-local address")
	}

	if isSupportedIPv6(net.ParseIP("ff02::2333")) {
		t.Errorf("isSupportedIPv6 return true with IPv6 link-local multicast address")
	}

	if !isSupportedIPv6(net.ParseIP("2001::1")) {
		t.Errorf("isSupportedIPv6 return false with IPv6 global unicast address")
	}
}

func TestCreateAddr(t *testing.T) {
	ipv4 := net.IP{127, 0, 0, 1}
	ipv6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
	port := 9000

	assert.Equal(t, &net.UDPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeUDP4, ipv4, port))
	assert.Equal(t, &net.UDPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeUDP6, ipv6, port))
	assert.Equal(t, &net.TCPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeTCP4, ipv4, port))
	assert.Equal(t, &net.TCPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeTCP6, ipv6, port))
}