-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicecontrol_test.go
67 lines (63 loc) · 1.45 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
package ice
import (
"testing"
"github.com/gortc/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")
}
})
}