-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathicecontrol_test.go
More file actions
105 lines (93 loc) · 2.97 KB
/
icecontrol_test.go
File metadata and controls
105 lines (93 loc) · 2.97 KB
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
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package ice
import (
"testing"
"github.com/pion/stun/v3"
"github.com/stretchr/testify/require"
)
func TestControlled_GetFrom(t *testing.T) { //nolint:dupl
m := new(stun.Message)
var attrCtr AttrControlled
require.ErrorIs(t, stun.ErrAttributeNotFound, attrCtr.GetFrom(m))
require.NoError(t, m.Build(stun.BindingRequest, &attrCtr))
m1 := new(stun.Message)
_, err := m1.Write(m.Raw)
require.NoError(t, err)
var c1 AttrControlled
require.NoError(t, c1.GetFrom(m1))
require.Equal(t, c1, attrCtr)
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlled, make([]byte, 100))
var c2 AttrControlled
require.True(t, stun.IsAttrSizeInvalid(c2.GetFrom(m3)))
})
}
func TestControlling_GetFrom(t *testing.T) { //nolint:dupl
m := new(stun.Message)
var attrCtr AttrControlling
require.ErrorIs(t, stun.ErrAttributeNotFound, attrCtr.GetFrom(m))
require.NoError(t, m.Build(stun.BindingRequest, &attrCtr))
m1 := new(stun.Message)
_, err := m1.Write(m.Raw)
require.NoError(t, err)
var c1 AttrControlling
require.NoError(t, c1.GetFrom(m1))
require.Equal(t, c1, attrCtr)
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 AttrControlling
require.True(t, stun.IsAttrSizeInvalid(c2.GetFrom(m3)))
})
}
func TestControl_GetFrom(t *testing.T) { //nolint:cyclop
t.Run("Blank", func(t *testing.T) {
m := new(stun.Message)
var c AttrControl
require.ErrorIs(t, stun.ErrAttributeNotFound, c.GetFrom(m))
})
t.Run("Controlling", func(t *testing.T) { //nolint:dupl
m := new(stun.Message)
var attCtr AttrControl
require.ErrorIs(t, stun.ErrAttributeNotFound, attCtr.GetFrom(m))
attCtr.Role = Controlling
attCtr.Tiebreaker = 4321
require.NoError(t, m.Build(stun.BindingRequest, &attCtr))
m1 := new(stun.Message)
_, err := m1.Write(m.Raw)
require.NoError(t, err)
var c1 AttrControl
require.NoError(t, c1.GetFrom(m1))
require.Equal(t, c1, attCtr)
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 AttrControl
err := c2.GetFrom(m3)
require.True(t, stun.IsAttrSizeInvalid(err))
})
})
t.Run("Controlled", func(t *testing.T) { //nolint:dupl
m := new(stun.Message)
var attrCtrl AttrControl
require.ErrorIs(t, stun.ErrAttributeNotFound, attrCtrl.GetFrom(m))
attrCtrl.Role = Controlled
attrCtrl.Tiebreaker = 1234
require.NoError(t, m.Build(stun.BindingRequest, &attrCtrl))
m1 := new(stun.Message)
_, err := m1.Write(m.Raw)
require.NoError(t, err)
var c1 AttrControl
require.NoError(t, c1.GetFrom(m1))
require.Equal(t, c1, attrCtrl)
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 AttrControl
err := c2.GetFrom(m3)
require.True(t, stun.IsAttrSizeInvalid(err))
})
})
}