-
Notifications
You must be signed in to change notification settings - Fork 53
/
netutils_test.go
62 lines (47 loc) · 1.29 KB
/
netutils_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package srtgo
import (
"testing"
"golang.org/x/sys/unix"
)
func TestCreateAddrInetV4(t *testing.T) {
ip1, size, err := CreateAddrInet("0.0.0.0", 8090)
if err != nil {
t.Error("Error on CreateAddrInet")
}
if size != 16 {
t.Error("Ip Address size does not match", size)
}
if ip1.sa_family != unix.AF_INET {
t.Error("Ip Address family does not match")
}
data := []int{31, -102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
if len(data) != len(ip1.sa_data) {
t.Error("Ip Address ip.sa_data length should be equal")
}
for i := 0; i < len(data); i++ {
if data[i] != int(ip1.sa_data[i]) {
t.Error("Ip Address ip.sa_data does not match")
}
}
}
func TestCreateAddrInetV6(t *testing.T) {
ip1, size, err := CreateAddrInet("2001:0db8:85a3:0000:0000:8a2e:0370:7334", 8090)
if err != nil {
t.Error("Error on CreateAddrInet")
}
if size != 28 {
t.Error("Ipv6 Address size does not match", size)
}
if ip1.sa_family != unix.AF_INET6 {
t.Error("Ipv6 Address family does not match")
}
data := []int{31, -102, 0, 0, 0, 0, 32, 1, 13, -72, -123, -93, 0, 0}
if len(data) != len(ip1.sa_data) {
t.Error("Ipv6 Address ip.sa_data length should be equal")
}
for i := 0; i < len(data); i++ {
if data[i] != int(ip1.sa_data[i]) {
t.Error("Ipv6 Address ip.sa_data does not match")
}
}
}