-
Notifications
You must be signed in to change notification settings - Fork 5
/
playlist_test.go
60 lines (54 loc) · 1.7 KB
/
playlist_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
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"testing"
)
func TestGetPlaylist(t *testing.T) {
testUsername := "testing"
token := &accessToken{
Value: "token",
Signature: "sig",
}
client := NewTestClient(func(req *http.Request) *http.Response {
equals(t, fmt.Sprintf(playlistURL, testUsername),
req.URL.String()[:len(req.URL.String())-len(req.URL.RawQuery)-1])
equals(t, "true", req.URL.Query().Get("allow_source"))
equals(t, "true", req.URL.Query().Get("fast_bread"))
equals(t, token.Signature, req.URL.Query().Get("sig"))
equals(t, token.Value, req.URL.Query().Get("token"))
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(bytes.NewBufferString(`#EXTM3U
#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="chunked",NAME="1080p60 (source)",AUTOSELECT=YES,DEFAULT=YES
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1234567,RESOLUTION=1920x1080,CODECS="avc1.64002A,mp4a.40.2",VIDEO="chunked",FRAME-RATE=60.000
https://example.invalid/123.m3u8
#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="720p60",NAME="720p60",AUTOSELECT=YES,DEFAULT=YES
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7654321,RESOLUTION=1280x720,CODECS="avc1.4D401F,mp4a.40.2",VIDEO="720p60",FRAME-RATE=60.000
https://example.invalid/456.m3u8`)),
Header: make(http.Header),
}
})
playlists, err := getPlaylists(client, testUsername, token)
ok(t, err)
equals(t, []playlistInfo{
{
Group: "chunked",
Name: "1080p60 (source)",
Bandwidth: 1234567,
Width: 1920,
Height: 1080,
URL: "https://example.invalid/123.m3u8",
},
{
Group: "720p60",
Name: "720p60",
Bandwidth: 7654321,
Width: 1280,
Height: 720,
URL: "https://example.invalid/456.m3u8",
},
}, playlists)
}