forked from kkdai/youtube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
86 lines (78 loc) · 1.77 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package youtube
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var testClient = Client{Debug: true}
const (
dwlURL string = "https://www.youtube.com/watch?v=rFejpH_tAHM"
streamURL string = "https://www.youtube.com/watch?v=5qap5aO4i9A"
errURL string = "https://www.youtube.com/watch?v=I8oGsuQ"
)
func TestParseVideo(t *testing.T) {
video, err := testClient.GetVideo(dwlURL)
assert.NoError(t, err)
assert.NotNil(t, video)
_, err = testClient.GetVideo(errURL)
assert.EqualError(t, err, `response status: 'fail', reason: 'Invalid parameters.'`)
}
func TestYoutube_findVideoID(t *testing.T) {
type args struct {
url string
}
tests := []struct {
name string
args args
wantErr bool
expectedErr error
}{
{
name: "valid url",
args: args{
dwlURL,
},
wantErr: false,
expectedErr: nil,
},
{
name: "valid id",
args: args{
"rFejpH_tAHM",
},
wantErr: false,
expectedErr: nil,
},
{
name: "invalid character in id",
args: args{
"<M13",
},
wantErr: true,
expectedErr: ErrInvalidCharactersInVideoID,
},
{
name: "video id is less than 10 characters",
args: args{
"rFejpH",
},
wantErr: true,
expectedErr: ErrVideoIDMinLength,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _, err := extractVideoID(tt.args.url); (err != nil) != tt.wantErr || err != tt.expectedErr {
t.Errorf("extractVideoID() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestGetVideo(t *testing.T) {
require := require.New(t)
video, err := testClient.GetVideo(streamURL)
require.NoError(err)
require.NotNil(video)
require.NotEmpty(video.HLSManifestURL)
require.NotEmpty(video.DASHManifestURL)
}