harden ffmpeg pipeline failure handling and stream mapping

This commit is contained in:
2026-04-21 23:07:48 +02:00
parent beb6ce6cbb
commit d65dc182f8
6 changed files with 173 additions and 14 deletions

View File

@@ -2,9 +2,11 @@ package app
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
@@ -20,6 +22,12 @@ type noopTagger struct{}
func (n noopTagger) TagFLAC(string, tag.Metadata, string) error { return nil }
type failingTagger struct {
err error
}
func (f failingTagger) TagFLAC(string, tag.Metadata, string) error { return f.err }
type fakeProvider struct {
url string
}
@@ -237,6 +245,56 @@ func TestTrackRipPipeline(t *testing.T) {
}
}
func TestTrackRipFailsWhenTaggerReportsMissingFFmpeg(t *testing.T) {
tmp := t.TempDir()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("audio-bytes"))
}))
defer ts.Close()
d := config.DefaultConfigData()
d.Downloads.Folder = tmp
d.Downloads.SourceSubdirectories = false
cfg := &config.Config{File: d, Session: d}
sqlite, err := store.NewSQLite(filepath.Join(tmp, "db.sqlite"))
if err != nil {
t.Fatalf("NewSQLite() error = %v", err)
}
defer func() { _ = sqlite.Close() }()
m := &Main{
Config: cfg,
Providers: map[string]provider.Client{
"qobuz": &fakeProvider{url: ts.URL},
},
Store: sqlite,
DL: download.NewWithOptions(true, false),
Tagger: failingTagger{err: fmt.Errorf("ffmpeg not found: %w", exec.ErrNotFound)},
}
ctx := context.Background()
if err = m.AddByID(ctx, "qobuz", "track", "19512574"); err != nil {
t.Fatalf("AddByID() error = %v", err)
}
if err = m.Resolve(ctx); err != nil {
t.Fatalf("Resolve() error = %v", err)
}
err = m.Rip(ctx)
if err == nil {
t.Fatalf("expected rip failure")
}
ok, err := sqlite.IsDownloaded(ctx, "qobuz", "19512574")
if err != nil {
t.Fatalf("IsDownloaded() error = %v", err)
}
if ok {
t.Fatalf("expected track not marked downloaded")
}
}
func TestAlbumRipPipeline(t *testing.T) {
tmp := t.TempDir()