This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker_test.go
101 lines (96 loc) · 2.56 KB
/
worker_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
94
95
96
97
98
99
100
101
// Copyright 2018 Francisco Souza. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sprite
import (
"testing"
"time"
)
func TestWorkerInputURL(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input workerInput
expected string
}{
{
"exact duration, width and height",
workerInput{
prefix: "https://video-packager.example.com/video/t/something/",
width: 128,
height: 72,
timecode: 2 * time.Second,
},
"https://video-packager.example.com/video/t/something/thumb-2000-w128-h72.jpg",
},
{
"duration, width and height + black bars",
workerInput{
prefix: "https://video-packager.example.com/video/t/something/",
width: 128,
height: 72,
timecode: 2 * time.Second,
letterbox: true,
},
"https://video-packager.example.com/video/t/something/thumb-2000-h72.jpg",
},
{
"non-exact duration, width and height",
workerInput{
prefix: "https://video-packager.example.com/video/t/something/",
width: 96,
height: 72,
timecode: 2531*time.Millisecond + 2531,
},
"https://video-packager.example.com/video/t/something/thumb-2531-w96-h72.jpg",
},
{
"no width",
workerInput{
prefix: "https://video-packager.example.com/video/t/something/",
height: 72,
timecode: 2 * time.Second,
},
"https://video-packager.example.com/video/t/something/thumb-2000-h72.jpg",
},
{
"no height",
workerInput{
prefix: "https://video-packager.example.com/video/t/something/",
width: 128,
timecode: 12 * time.Second,
},
"https://video-packager.example.com/video/t/something/thumb-12000-w128.jpg",
},
{
"no width or height",
workerInput{
prefix: "https://video-packager.example.com/video/t/something/",
timecode: 2 * time.Second,
},
"https://video-packager.example.com/video/t/something/thumb-2000.jpg",
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
url := test.input.url()
if url != test.expected {
t.Errorf("wrong url returned\nwant %q\ngot %q", test.expected, url)
}
})
}
}
func TestVideoPackagerError(t *testing.T) {
t.Parallel()
var err error = &VideoPackagerError{
StatusCode: 400,
ResponseBody: []byte("nope"),
}
const expectedMsg = "invalid response from video-packager: 400 - nope"
errMsg := err.Error()
if errMsg != expectedMsg {
t.Errorf("invalid error message generated by VideoPackagerError\nwant %q\ngot %q", expectedMsg, errMsg)
}
}