-
Notifications
You must be signed in to change notification settings - Fork 0
/
info_test.go
84 lines (72 loc) · 1.81 KB
/
info_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
package mediaprobe_test
import (
"net/http"
"testing"
"github.com/Arimeka/mediaprobe"
)
func TestNew(t *testing.T) {
t.Run("not_found", newNotFound)
t.Run("not_found_remote", newNotFoundRemote)
t.Run("conn_error_remote", newConnErrorRemote)
t.Run("server_error_remote", newServerErrorRemote)
t.Run("local", newLocalFile)
t.Run("remote", newRemoteFile)
}
func newNotFound(t *testing.T) {
_, err := mediaprobe.New("")
if err == nil {
t.Errorf("Expected to return error found but return nil")
}
}
func newNotFoundRemote(t *testing.T) {
handler := &Handler{
Status: http.StatusNotFound,
}
srv := ServeHttp(handler)
defer srv.Stop()
_, err := mediaprobe.New(srv.Endpoint())
if err == nil {
t.Errorf("Expected to return error found but return nil")
}
}
func newConnErrorRemote(t *testing.T) {
_, err := mediaprobe.New("http://localhost:9091/not-exist")
if err == nil {
t.Errorf("Expected to return error found but return nil")
}
}
func newServerErrorRemote(t *testing.T) {
handler := &Handler{
Filename: "./fixtures/video.mp4",
FailOnAttempt: 1,
}
srv := ServeHttp(handler)
defer srv.Stop()
_, err := mediaprobe.New(srv.Endpoint())
if err == nil {
t.Errorf("Expected to return error found but return nil")
}
}
func newLocalFile(t *testing.T) {
info, err := mediaprobe.New("./fixtures/video.mp4")
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if info.Size != 383631 {
t.Errorf("Unexpected size. Expected %d, got %d", 383631, info.Size)
}
}
func newRemoteFile(t *testing.T) {
handler := &Handler{
Filename: "./fixtures/video.mp4",
}
srv := ServeHttp(handler)
defer srv.Stop()
info, err := mediaprobe.New(srv.Endpoint())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if info.Size != 383631 {
t.Errorf("Unexpected size. Expected %d, got %d", 383631, info.Size)
}
}