-
Notifications
You must be signed in to change notification settings - Fork 0
/
turn_test.go
47 lines (36 loc) · 1 KB
/
turn_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
package turn
import (
"testing"
"time"
"github.com/gortc/turn"
"github.com/pion/stun"
)
func TestAllocationLifeTime(t *testing.T) {
lifetime := turn.Lifetime{
Duration: 5 * time.Second,
}
m := &stun.Message{}
lifetimeDuration := allocationLifeTime(m)
if lifetimeDuration != turn.DefaultLifetime {
t.Errorf("Allocation lifetime should be default time duration")
}
if err := lifetime.AddTo(m); err != nil {
t.Errorf("Lifetime add to message failed: %v", err)
}
lifetimeDuration = allocationLifeTime(m)
if lifetimeDuration != lifetime.Duration {
t.Errorf("Expect lifetimeDuration is %s, but %s", lifetime.Duration, lifetimeDuration)
}
// If lifetime is bigger than maximumLifetime
{
lifetime := turn.Lifetime{
Duration: maximumLifetime * 2,
}
m2 := &stun.Message{}
_ = lifetime.AddTo(m2)
lifetimeDuration := allocationLifeTime(m2)
if lifetimeDuration != turn.DefaultLifetime {
t.Errorf("Expect lifetimeDuration is %s, but %s", turn.DefaultLifetime, lifetimeDuration)
}
}
}