sonda/internal/library/plan_test.go
tgiachi d6e9e09ce7 fix(library): harden the scanner against special files, stat errors and lossy logging
- fix: skip FIFOs, sockets and devices named like audio files; opening a named
  pipe blocked a scan forever and left the manager stuck in "running"
- fix: a file that cannot be stat'ed for a transient reason is unknown, not
  gone, so it is never marked missing or used as a rename source
- fix: log the scan result from Manager.OnFinish instead of the lossy event
  hub, so the line can no longer be dropped
- fix(storage): match artists and albums on a Unicode-aware key computed in Go
  (migration 0003, both drivers), so SQLite and PostgreSQL agree
- test: FIFO, stat errors, OnFinish, Unicode artist and album matching
2026-11-11 12:28:44 +01:00

31 lines
1 KiB
Go

package library
import "testing"
// A file whose stat failed for a transient reason is unknown, not gone.
func TestPlanDoesNotFlagFilesWithStatErrors(t *testing.T) {
existing := []ExistingFile{
{ID: 1, FileInfo: FileInfo{RelPath: "flaky.mp3", Size: 10, MTimeUnix: 5}},
{ID: 2, FileInfo: FileInfo{RelPath: "gone.mp3", Size: 20, MTimeUnix: 6}},
}
w := walkResult{
files: []FileInfo{{RelPath: "new.mp3", Size: 10, MTimeUnix: 5}}, // same size+mtime as flaky.mp3
failedFiles: map[string]bool{"flaky.mp3": true},
}
p := makePlan(w, existing)
for _, id := range p.missing {
if id == 1 {
t.Error("flaky.mp3 was marked missing after a stat error")
}
}
if len(p.renames) != 0 {
t.Errorf("renames = %+v: a file with a stat error must not be a rename source", p.renames)
}
if len(p.missing) != 1 || p.missing[0] != 2 {
t.Errorf("missing = %v, want only gone.mp3", p.missing)
}
if len(p.parse) != 1 || p.parse[0].file.RelPath != "new.mp3" {
t.Errorf("parse = %+v, want new.mp3 as a new file", p.parse)
}
}