forked from lithdew/youtube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
60 lines (47 loc) · 1.18 KB
/
client_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 youtube
import (
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
"net/url"
"strconv"
"testing"
)
func TestLoadEmbedPlayer(t *testing.T) {
client := NewClient()
p, err := client.LoadEmbedPlayer("pAsDzfbLM8Y")
require.NoError(t, err)
require.NotZero(t, p)
}
func BenchmarkURLAppend(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
id := "hello_world"
offset := uint(12)
for i := 0; i < b.N; i++ {
uri := []byte("https://www.youtube.com/list_ajax?style=json&action_get_list=1")
uri = append(uri, "&list="...)
uri = append(uri, id...)
uri = append(uri, "&index="...)
uri = fasthttp.AppendUint(uri, int(offset))
uri = append(uri, "&hl="...)
uri = append(uri, "en"...)
}
}
func BenchmarkURLValues(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
id := "hello_world"
offset := uint(12)
for i := 0; i < b.N; i++ {
uri := []byte("https://www.youtube.com/list_ajax?")
uri = append(uri,
url.Values{
"style": {"json"},
"action_get_list": {strconv.FormatUint(1, 10)},
"list": {id},
"index": {strconv.FormatUint(uint64(offset), 10)},
"hl": {"en"},
}.Encode()...,
)
}
}