media_probe_test.go
⎇
Raw
1package service
2
3import (
4 "path/filepath"
5 "testing"
6)
7
8func TestParseFPS(t *testing.T) {
9 tests := []struct{ in, want string }{
10 {"30/1", "30"},
11 {"30000/1001", "29.97"},
12 {"0/0", ""},
13 {"", ""},
14 {"garbage", ""},
15 }
16 for _, tc := range tests {
17 if got := parseFPS(tc.in); got != tc.want {
18 t.Errorf("parseFPS(%q) = %q, want %q", tc.in, got, tc.want)
19 }
20 }
21}
22
23func TestFormatBitrate(t *testing.T) {
24 tests := []struct{ in, want string }{
25 {"128000", "128"},
26 {"", ""},
27 {"notanumber", ""},
28 }
29 for _, tc := range tests {
30 if got := formatBitrate(tc.in); got != tc.want {
31 t.Errorf("formatBitrate(%q) = %q, want %q", tc.in, got, tc.want)
32 }
33 }
34}
35
36func TestGetMetadataForSelectedFile(t *testing.T) {
37 requireFFmpeg(t)
38 svc, dir := newLibrary(t)
39 itemDir := writeItem(t, dir, "multi", "name = \"M\"\nduration = -1\n", nil)
40 makeTestVideoSize(t, filepath.Join(itemDir, "small.mp4"), "64x64")
41 makeTestVideoSize(t, filepath.Join(itemDir, "big.mp4"), "128x72")
42
43 m1, err := svc.GetMetadata("multi", "small.mp4")
44 if err != nil {
45 t.Fatalf("GetMetadata small: %v", err)
46 }
47 if m1.Resolution != "64x64" {
48 t.Errorf("small.mp4 resolution = %q, want 64x64", m1.Resolution)
49 }
50 m2, err := svc.GetMetadata("multi", "big.mp4")
51 if err != nil {
52 t.Fatalf("GetMetadata big: %v", err)
53 }
54 if m2.Resolution != "128x72" {
55 t.Errorf("big.mp4 resolution = %q, want 128x72", m2.Resolution)
56 }
57}
58