forked from iawia002/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
62 lines (55 loc) 路 1.32 KB
/
utils.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
package test
import (
"fmt"
"sort"
"testing"
"github.com/wanyuqin/lux/extractors"
)
// Args Arguments for extractor tests
type Args struct {
URL string
Title string
Quality string
Size int64
}
// CheckData check the given data
func CheckData(args, data Args) bool {
if args.Title != data.Title {
return false
}
// not every video got quality information
if args.Quality != "" && args.Quality != data.Quality {
return false
}
if args.Size != 0 && args.Size != data.Size {
return false
}
return true
}
// Check check the result
func Check(t *testing.T, args Args, data *extractors.Data) {
// get the default stream
sortedStreams := make([]*extractors.Stream, 0, len(data.Streams))
for _, s := range data.Streams {
sortedStreams = append(sortedStreams, s)
}
if len(sortedStreams) == 0 {
t.Fatalf("stream should not empty")
}
sort.SliceStable(sortedStreams, func(i, j int) bool { return sortedStreams[i].Size > sortedStreams[j].Size })
defaultData := sortedStreams[0]
temp := Args{
Title: data.Title,
Quality: defaultData.Quality,
Size: defaultData.Size,
}
if !CheckData(args, temp) {
t.Errorf("Got: %v\nExpected: %v", temp, args)
}
}
// CheckError check the error
func CheckError(t *testing.T, err error) {
if err != nil {
t.Fatalf("Unexpected error:\n%s", fmt.Sprintf("%+v\n", err))
}
}