package service import ( "path/filepath" "testing" ) func TestParseFPS(t *testing.T) { tests := []struct{ in, want string }{ {"30/1", "30"}, {"30000/1001", "29.97"}, {"0/0", ""}, {"", ""}, {"garbage", ""}, } for _, tc := range tests { if got := parseFPS(tc.in); got != tc.want { t.Errorf("parseFPS(%q) = %q, want %q", tc.in, got, tc.want) } } } func TestFormatBitrate(t *testing.T) { tests := []struct{ in, want string }{ {"128000", "128"}, {"", ""}, {"notanumber", ""}, } for _, tc := range tests { if got := formatBitrate(tc.in); got != tc.want { t.Errorf("formatBitrate(%q) = %q, want %q", tc.in, got, tc.want) } } } func TestGetMetadataForSelectedFile(t *testing.T) { requireFFmpeg(t) svc, dir := newLibrary(t) itemDir := writeItem(t, dir, "multi", "name = \"M\"\nduration = -1\n", nil) makeTestVideoSize(t, filepath.Join(itemDir, "small.mp4"), "64x64") makeTestVideoSize(t, filepath.Join(itemDir, "big.mp4"), "128x72") m1, err := svc.GetMetadata("multi", "small.mp4") if err != nil { t.Fatalf("GetMetadata small: %v", err) } if m1.Resolution != "64x64" { t.Errorf("small.mp4 resolution = %q, want 64x64", m1.Resolution) } m2, err := svc.GetMetadata("multi", "big.mp4") if err != nil { t.Fatalf("GetMetadata big: %v", err) } if m2.Resolution != "128x72" { t.Errorf("big.mp4 resolution = %q, want 128x72", m2.Resolution) } }