forked from pion/ice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
41 lines (32 loc) · 1.29 KB
/
util_test.go
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))
}