forked from pion/mediadevices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track_test.go
55 lines (46 loc) · 1.05 KB
/
track_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
package mediadevices
import (
"errors"
"testing"
"time"
)
func TestOnEnded(t *testing.T) {
errExpected := errors.New("an error")
t.Run("ErrorAfterRegister", func(t *testing.T) {
tr := &baseTrack{}
called := make(chan error, 1)
tr.OnEnded(func(error) {
called <- errExpected
})
select {
case <-called:
t.Error("OnEnded handler is unexpectedly called")
case <-time.After(10 * time.Millisecond):
}
tr.onError(errExpected)
select {
case err := <-called:
if err != errExpected {
t.Errorf("Expected to receive error: %v, got: %v", errExpected, err)
}
case <-time.After(10 * time.Millisecond):
t.Error("Timeout")
}
})
t.Run("ErrorBeforeRegister", func(t *testing.T) {
tr := &baseTrack{}
tr.onError(errExpected)
called := make(chan error, 1)
tr.OnEnded(func(err error) {
called <- errExpected
})
select {
case err := <-called:
if err != errExpected {
t.Errorf("Expected to receive error: %v, got: %v", errExpected, err)
}
case <-time.After(10 * time.Millisecond):
t.Error("Timeout")
}
})
}