This commit is contained in:
2026-08-23 14:13:18 -05:00
parent 789bf91eed
commit 866f243f1b
37 changed files with 1761 additions and 58 deletions
+28
View File
@@ -1,6 +1,7 @@
package coverart
import (
"context"
"image"
"image/color"
"image/jpeg"
@@ -9,6 +10,33 @@ import (
"testing"
)
func TestExtractEmbeddedSuppliesExplicitOutputFormat(t *testing.T) {
dir := t.TempDir()
argsPath := filepath.Join(dir, "args")
fakeFFmpeg := filepath.Join(dir, "ffmpeg")
script := "#!/bin/sh\nprintf '%s\\n' \"$@\" > \"$ARGS_PATH\"\n"
if err := os.WriteFile(fakeFFmpeg, []byte(script), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("ARGS_PATH", argsPath)
store := New(dir, fakeFFmpeg)
path, err := store.ExtractEmbedded(context.Background(), filepath.Join(dir, "song.mp3"), 2)
if err != nil {
t.Fatalf("ExtractEmbedded: %v", err)
}
defer os.Remove(path)
args, err := os.ReadFile(argsPath)
if err != nil {
t.Fatal(err)
}
got := string(args)
if got != "-y\n-v\nerror\n-i\n"+filepath.Join(dir, "song.mp3")+"\n-map\n0:2\n-frames:v\n1\n-c:v\ncopy\n-f\nimage2\n"+path+"\n" {
t.Fatalf("unexpected ffmpeg arguments:\n%s", got)
}
}
func writeTestJPEG(t *testing.T, path string, w, h int) {
t.Helper()
img := image.NewRGBA(image.Rect(0, 0, w, h))