forked from pires/go-proxyproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addr_proto_test.go
93 lines (85 loc) · 1.65 KB
/
addr_proto_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package proxyproto
import (
"testing"
)
func TestTCPoverIPv4(t *testing.T) {
b := byte(TCPv4)
if !AddressFamilyAndProtocol(b).IsIPv4() {
t.Fail()
}
if !AddressFamilyAndProtocol(b).IsStream() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}
func TestTCPoverIPv6(t *testing.T) {
b := byte(TCPv6)
if !AddressFamilyAndProtocol(b).IsIPv6() {
t.Fail()
}
if !AddressFamilyAndProtocol(b).IsStream() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}
func TestUDPoverIPv4(t *testing.T) {
b := byte(UDPv4)
if !AddressFamilyAndProtocol(b).IsIPv4() {
t.Fail()
}
if !AddressFamilyAndProtocol(b).IsDatagram() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}
func TestUDPoverIPv6(t *testing.T) {
b := byte(UDPv6)
if !AddressFamilyAndProtocol(b).IsIPv6() {
t.Fail()
}
if !AddressFamilyAndProtocol(b).IsDatagram() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}
func TestUnixStream(t *testing.T) {
b := byte(UnixStream)
if !AddressFamilyAndProtocol(b).IsUnix() {
t.Fail()
}
if !AddressFamilyAndProtocol(b).IsStream() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}
func TestUnixDatagram(t *testing.T) {
b := byte(UnixDatagram)
if !AddressFamilyAndProtocol(b).IsUnix() {
t.Fail()
}
if !AddressFamilyAndProtocol(b).IsDatagram() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}
func TestInvalidAddressFamilyAndProtocol(t *testing.T) {
b := byte(UNSPEC)
if !AddressFamilyAndProtocol(b).IsUnspec() {
t.Fail()
}
if AddressFamilyAndProtocol(b).toByte() != b {
t.Fail()
}
}