-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
50 lines (44 loc) · 1.1 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
package test
import (
"sort"
"testing"
"github.com/iawia002/annie/downloader"
)
// 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 downloader.Data) {
// get the default stream
sortedStreams := make([]downloader.Stream, len(data.Streams))
for _, data := range data.Streams {
sortedStreams = append(sortedStreams, data)
}
sort.Slice(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: %v", err)
}
}