fix scanner missing library errors

This commit is contained in:
ShukeBta
2026-07-01 23:21:49 +08:00
parent 0493823b99
commit 3bea1ca276
2 changed files with 34 additions and 2 deletions
@@ -1,12 +1,14 @@
package service
import (
"errors"
"os"
"path/filepath"
"testing"
"time"
"go.uber.org/zap"
"gorm.io/gorm"
"github.com/ShukeBta/MediaStationGo/internal/config"
"github.com/ShukeBta/MediaStationGo/internal/model"
@@ -61,6 +63,30 @@ func TestIngestPathAddsSingleFile(t *testing.T) {
}
}
func TestScanLibraryReturnsNotFoundForMissingLibrary(t *testing.T) {
sc, _ := newScannerTestEnv(t)
res, err := sc.ScanLibrary(t.Context(), "missing-library")
if err == nil {
t.Fatalf("ScanLibrary() error = nil, result = %#v", res)
}
if !errors.Is(err, gorm.ErrRecordNotFound) && err.Error() != "library not found" {
t.Fatalf("ScanLibrary() error = %v, want not found", err)
}
}
func TestIngestPathReturnsNotFoundForMissingLibrary(t *testing.T) {
sc, _ := newScannerTestEnv(t)
added, err := sc.IngestPath(t.Context(), "missing-library", filepath.Join(t.TempDir(), "movie.mkv"))
if err == nil {
t.Fatalf("IngestPath() error = nil, added = %v", added)
}
if !errors.Is(err, gorm.ErrRecordNotFound) && err.Error() != "library not found" {
t.Fatalf("IngestPath() error = %v, want not found", err)
}
}
func TestScanLibraryReadsLocalSTRMTarget(t *testing.T) {
sc, repos := newScannerTestEnv(t)
root := t.TempDir()