This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
icecontrol_test.go
139 lines (134 loc) · 3.18 KB
/
icecontrol_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package ice
import (
"testing"
"gortc.io/stun"
)
func TestControlled_GetFrom(t *testing.T) {
m := new(stun.Message)
var c AttrControlled
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
if err := m.Build(stun.BindingRequest, &c); err != nil {
t.Error(err)
}
m1 := new(stun.Message)
if _, err := m1.Write(m.Raw); err != nil {
t.Error(err)
}
var c1 AttrControlled
if err := c1.GetFrom(m1); err != nil {
t.Error(err)
}
if c1 != c {
t.Error("not equal")
}
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlled, make([]byte, 100))
var c2 AttrControlled
if err := c2.GetFrom(m3); !stun.IsAttrSizeInvalid(err) {
t.Error("should error")
}
})
}
func TestControlling_GetFrom(t *testing.T) {
m := new(stun.Message)
var c AttrControlling
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
if err := m.Build(stun.BindingRequest, &c); err != nil {
t.Error(err)
}
m1 := new(stun.Message)
if _, err := m1.Write(m.Raw); err != nil {
t.Error(err)
}
var c1 AttrControlling
if err := c1.GetFrom(m1); err != nil {
t.Error(err)
}
if c1 != c {
t.Error("not equal")
}
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 AttrControlling
if err := c2.GetFrom(m3); !stun.IsAttrSizeInvalid(err) {
t.Error("should error")
}
})
}
func TestControl_GetFrom(t *testing.T) {
t.Run("Blank", func(t *testing.T) {
m := new(stun.Message)
var c AttrControl
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
})
t.Run("Controlling", func(t *testing.T) {
m := new(stun.Message)
var c AttrControl
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
c.Role = Controlling
c.Tiebreaker = 4321
if err := m.Build(stun.BindingRequest, &c); err != nil {
t.Error(err)
}
m1 := new(stun.Message)
if _, err := m1.Write(m.Raw); err != nil {
t.Error(err)
}
var c1 AttrControl
if err := c1.GetFrom(m1); err != nil {
t.Error(err)
}
if c1 != c {
t.Error("not equal")
}
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 AttrControl
if err := c2.GetFrom(m3); !stun.IsAttrSizeInvalid(err) {
t.Error("should error")
}
})
})
t.Run("Controlled", func(t *testing.T) {
m := new(stun.Message)
var c AttrControl
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
c.Role = Controlled
c.Tiebreaker = 1234
if err := m.Build(stun.BindingRequest, &c); err != nil {
t.Error(err)
}
m1 := new(stun.Message)
if _, err := m1.Write(m.Raw); err != nil {
t.Error(err)
}
var c1 AttrControl
if err := c1.GetFrom(m1); err != nil {
t.Error(err)
}
if c1 != c {
t.Error("not equal")
}
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 AttrControl
if err := c2.GetFrom(m3); !stun.IsAttrSizeInvalid(err) {
t.Error("should error")
}
})
})
}