forked from livepeer/go-livepeer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideosource_test.go
65 lines (54 loc) · 2.04 KB
/
videosource_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
package core
import (
"testing"
"github.com/ericxtang/m3u8"
)
func TestGetMasterPlaylist(t *testing.T) {
c := NewBasicVideoSource()
pl := m3u8.NewMasterPlaylist()
pl.Append("test1.m3u8", nil, m3u8.VariantParams{Bandwidth: 100})
c.UpdateHLSMasterPlaylist("122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test", pl)
testpl := c.GetHLSMasterPlaylist("122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test")
if testpl.String() != pl.String() {
t.Errorf("Expecting %v, got %v", pl.String(), testpl.String())
}
}
func TestEvictMasterPlaylist(t *testing.T) {
c := NewBasicVideoSource()
pl := m3u8.NewMasterPlaylist()
pl.Append("test1.m3u8", nil, m3u8.VariantParams{Bandwidth: 100})
c.UpdateHLSMasterPlaylist("122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test", pl)
testpl := c.GetHLSMasterPlaylist("122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test")
if testpl.String() != pl.String() {
t.Errorf("Expecting %v, got %v", pl.String(), testpl.String())
}
c.EvictHLSMasterPlaylist("122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test")
testpl = c.GetHLSMasterPlaylist("122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test")
if testpl != nil {
t.Errorf("Expecting nil, got %v", testpl.String())
}
}
func TestGetAndEvictHLSMediaPlaylist(t *testing.T) {
c := NewBasicVideoSource()
strmID := "122011e494a06b20bf7a80f40e80d538675cc0b168c21912d33e0179617d5d4fe4e0Test"
pl := c.GetHLSMediaPlaylist(StreamID(strmID))
if pl != nil {
t.Errorf("Expecting nil as pl")
}
c.InsertHLSSegment(StreamID(strmID), &StubSegment().Seg)
pl = c.GetHLSMediaPlaylist(StreamID(strmID))
if pl == nil {
t.Errorf("Expecting pl, got nil")
return
}
s := pl.Segments[0]
if s.URI != "test.ts" {
t.Errorf("Expecting test.ts, got %v", s.URI)
}
//Test evict (first need to simulate that stream has stopped)
c.EvictHLSStream(StreamID(strmID))
pl = c.GetHLSMediaPlaylist(StreamID(strmID))
if pl != nil {
t.Errorf("Expecting no pl, got %v", pl)
}
}