feat: add DB-backed scanner entrypoint and compute-only main hook

Implements ScanArtist/ScanAll in internal/scanner loading local/external
releases via the database layer with ctx-cancellation checks, plus a
compute-only run() hook that logs missing-release counts. Add table-driven
tests using in-memory SQLite fixtures.
This commit is contained in:
2026-07-19 18:19:57 +03:00
parent a4f0460664
commit c2da8c2095
6 changed files with 348 additions and 8 deletions

View File

@@ -7,8 +7,54 @@ import (
"testing"
"naviwatcher/internal/config"
"naviwatcher/internal/database"
)
func TestAppRun_ScanLogsMissingReleases(t *testing.T) {
// Verify the compute-only run() hook scans monitored artists and returns
// nil without starting notifier/web. Uses an in-memory DB with one
// monitored artist that has one missing release.
db, err := database.New(":memory:")
if err != nil {
t.Fatalf("database.New() error: %v", err)
}
defer db.Close()
if err := database.SaveArtistSettings(db, &database.ArtistSettings{
ID: "artist-1",
Name: "Pink Floyd",
Monitored: true,
}); err != nil {
t.Fatalf("seed artist: %v", err)
}
if err := database.SaveLocalAlbum(db, &database.LocalAlbum{
ID: "l1",
ArtistID: "artist-1",
Title: "The Wall",
}); err != nil {
t.Fatalf("seed local album: %v", err)
}
if err := database.SaveExternalRelease(db, &database.ExternalRelease{
RGID: "rg2",
ArtistID: "artist-1",
Title: "Animals",
}); err != nil {
t.Fatalf("seed external release: %v", err)
}
app := &App{
cfg: &config.Config{Scanner: config.ScannerConfig{FuzzyThreshold: 0.85}},
db: db,
}
ctx, cancel := context.WithCancel(context.Background())
cancel() // cancel immediately so run() exits after scanning
if err := app.run(ctx); err != nil {
t.Fatalf("app.run() returned error: %v", err)
}
}
func TestConfigIntegration(t *testing.T) {
// Integration test: write a minimal valid config and load it via config.LoadConfig,
// verifying the full path that main() uses.