-
Notifications
You must be signed in to change notification settings - Fork 0
/
probe_test.go
118 lines (105 loc) · 3.45 KB
/
probe_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package mediaprobe_test
import (
"testing"
"github.com/Arimeka/mediaprobe"
)
const (
testProbeValidRemoteImage = "http://localhost:9097/image.jpeg"
testProbeValidImage = "./fixtures/image.jpeg"
testProbeInvalidImage = "./fixtures/not-an-image.jpeg"
testProbeValidVideo = "./fixtures/video.mp4"
testProbeInvalidVideo = "./fixtures/not-a-video.mp4"
testProbeValidAudio = "./fixtures/audio.mp3"
testProbeCorruptedFile = "./fixtures/corrupted.mp4"
)
func TestParse(t *testing.T) {
t.Run("not_found", parseNotFound)
t.Run("valid_remote_image", parseValidRemoteImage)
t.Run("valid_image", parseValidImage)
t.Run("invalid_image", parseInvalidImage)
t.Run("valid_video", parseValidVideo)
t.Run("invalid_video", parseInvalidVideo)
t.Run("valid_audio", parseValidAudio)
t.Run("corrupted_file", parseCorruptedFile)
}
func parseNotFound(t *testing.T) {
_, err := mediaprobe.Parse("")
if err == nil {
t.Errorf("Expected to return error found but return nil")
}
}
func parseValidImage(t *testing.T) {
info, err := mediaprobe.Parse(testProbeValidImage)
if err != nil {
t.Errorf("Filename: %s. Unexpected error %v", testProbeValidImage, err)
}
width := info.Width
if width != 290 {
t.Errorf("Filename: %s. Not expected width. Expected %d; got %d", testProbeValidImage, 290, width)
}
}
func parseValidRemoteImage(t *testing.T) {
handler := &Handler{
Filename: "./fixtures/image.jpeg",
}
srv := ServeHttp(handler)
defer srv.Stop()
info, err := mediaprobe.Parse(srv.Endpoint())
if err != nil {
t.Errorf("Unexpected error %v", err)
}
width := info.Width
if width != 290 {
t.Errorf("Filename: %s. Not expected width. Expected %d; got %d", testProbeValidRemoteImage, 290, width)
}
}
func parseInvalidImage(t *testing.T) {
info, err := mediaprobe.Parse(testProbeInvalidImage)
if err != nil {
t.Errorf("Filename: %s. Unexpected error %v", testProbeInvalidImage, err)
}
bitrate := info.BitRate
if bitrate != 551193 {
t.Errorf("Filename: %s. Not expected video bitrate. Expected %d; got %d", testProbeInvalidImage, 551193, bitrate)
}
}
func parseValidVideo(t *testing.T) {
info, err := mediaprobe.Parse(testProbeValidVideo)
if err != nil {
t.Errorf("Filename: %s. Unexpected error %v", testProbeValidVideo, err)
}
bitrate := info.BitRate
if bitrate != 551193 {
t.Errorf("Filename: %s. Not expected video bitrate. Expected %d; got %d", testProbeValidVideo, 551193, bitrate)
}
}
func parseInvalidVideo(t *testing.T) {
info, err := mediaprobe.Parse(testProbeInvalidVideo)
if err != nil {
t.Errorf("Filename: %s. Unexpected error %v", testProbeInvalidVideo, err)
}
width := info.Width
if width != 290 {
t.Errorf("Filename: %s. Not expected width. Expected %d; got %d", testProbeInvalidVideo, 290, width)
}
}
func parseValidAudio(t *testing.T) {
info, err := mediaprobe.Parse(testProbeValidAudio)
if err != nil {
t.Errorf("Filename: %s. Unexpected error %v", testProbeValidAudio, err)
}
bitrate := info.BitRate
if bitrate != 128000 {
t.Errorf("Filename: %s. Not expected video bitrate. Expected %d; got %d", testProbeValidAudio, 128000, bitrate)
}
}
func parseCorruptedFile(t *testing.T) {
info, err := mediaprobe.Parse(testProbeCorruptedFile)
if err != nil {
t.Errorf("Filename: %s. Unexpected error %v", testProbeCorruptedFile, err)
}
mediaSubtype := info.MediaSubtype
if mediaSubtype != "octet-stream" {
t.Errorf("Filename: %s. Not media subtype. Expected %s; got %s", testProbeValidAudio, "octet-stream", mediaSubtype)
}
}