-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtwitchdl_test.go
93 lines (88 loc) · 1.87 KB
/
twitchdl_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
87
88
89
90
91
92
93
package twitchdl
import (
"fmt"
"testing"
"time"
"github.com/jybp/twitch-downloader/m3u8"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSliceSegments(t *testing.T) {
segments := []m3u8.MediaSegment{
{Number: 0, Duration: time.Second * 5},
{Number: 1, Duration: time.Second * 5},
{Number: 2, Duration: time.Second * 5},
{Number: 3, Duration: time.Second * 5},
}
tcs := []struct {
start time.Duration
end time.Duration
expected []int
expectedErr bool
}{
{
start: time.Second * 2,
end: time.Second,
expectedErr: true,
},
{
start: time.Second * 8,
end: time.Second * 8,
expectedErr: true,
},
{
start: -time.Second * 2,
end: -time.Second,
expectedErr: true,
},
{
start: time.Second * 20,
end: time.Second * 21,
expectedErr: true,
},
{
start: time.Duration(0),
end: time.Duration(0),
expected: []int{0, 1, 2, 3},
},
{
start: time.Second * 5,
end: time.Duration(0),
expected: []int{1, 2, 3},
},
{
start: time.Duration(0),
end: time.Second * 5,
expected: []int{0},
},
{
start: time.Second * 6,
end: time.Second * 10,
expected: []int{1},
},
{
start: time.Second * 6,
end: time.Second * 11,
expected: []int{1, 2},
},
{
start: time.Second * 6,
end: time.Second * 22,
expected: []int{1, 2, 3},
},
}
for _, tc := range tcs {
t.Run(fmt.Sprintf("start: %v end: %v", tc.start, tc.end), func(t *testing.T) {
actual, err := sliceSegments(segments, tc.start, tc.end)
if tc.expectedErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Len(t, actual, len(tc.expected))
for i := 0; i < len(actual); i++ {
assert.Equal(t, tc.expected[i], actual[i].Number)
}
})
}
}