-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathmain_test.go
51 lines (49 loc) · 1.39 KB
/
main_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
package main
import (
"bytes"
"testing"
)
func TestCommandLines(t *testing.T) {
tmpDir := t.TempDir()
outFile := tmpDir + "/cropped.mp4"
cases := []struct {
desc string
args []string
expectedErr bool
wantedOutput string
}{
{desc: "help", args: []string{appName, "-h"}, expectedErr: false},
{desc: "no args", args: []string{appName}, expectedErr: true},
{desc: "duration = 0", args: []string{appName, "-d", "0", "dummy.mp4", "dummy.mp4"}, expectedErr: true},
{desc: "non-existing infile", args: []string{appName, "-d", "1000", "notExists.mp4", "dummy.mp4"}, expectedErr: true},
{desc: "segment 2s to 1s (30fps 3000 ticks/frame)", args: []string{appName, "-v", "-d", "90000", "../../mp4/testdata/1.m4s", outFile},
wantedOutput: `Started segment 1 at dts=0 pts=6000
0 DTS 0 PTS 6000
30 DTS 90000 PTS 96000
Started segment 2 at dts=90000 pts=96000
`,
expectedErr: false},
}
for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
buf := bytes.Buffer{}
err := run(c.args, &buf)
if c.expectedErr {
if err == nil {
t.Error("expected error but got nil")
}
return
}
if err != nil {
t.Errorf("unexpected error: %s", err)
return
}
if c.wantedOutput != "" {
gotOutput := buf.String()
if gotOutput != c.wantedOutput {
t.Errorf("unexpected output: got %s, wanted %s", gotOutput, c.wantedOutput)
}
}
})
}
}