sonda/internal/library/special_unix_test.go
tgiachi 46463846b3 feat(library): named media libraries managed through the API
- feat(storage): libraries table (name, path); audio_files points at a library
  by id instead of repeating the root path; migration 0005 for both drivers
  turns every existing root into a library and keeps file ids, tracks and the
  missing flag
- feat(library): Libraries service validates names and paths: absolute, an
  existing directory, never the filesystem root, never inside or around
  another library (checked on real paths, so symlinks cannot hide an overlap)
- feat(api): admin-only GET/POST /libraries, PATCH/DELETE /libraries/{id} and
  POST /libraries/{id}/scan; deleting a library drops its index entries and
  keeps tracks and listening history
- feat(library): the scanner and the scan manager work on libraries; scanning
  with no libraries answers 409 no_libraries
- feat(streaming): the library directory comes from the database instead of
  a configured list of roots
- breaking(config): library.roots is removed; an old config fails with a hint
  to use POST /api/v1/libraries
- test: CRUD and duplicates on both databases, path change keeps files,
  upgrade of a database written before libraries existed
2026-11-11 13:30:25 +01:00

48 lines
1,022 B
Go

//go:build unix
package library
import (
"context"
"path/filepath"
"syscall"
"testing"
"time"
)
// A named pipe called *.mp3 blocks forever on open if anything reads it.
func TestSpecialFilesAreSkipped(t *testing.T) {
root := t.TempDir()
write(t, filepath.Join(root, "real.mp3"), "1")
if err := syscall.Mkfifo(filepath.Join(root, "pipe.mp3"), 0o644); err != nil {
t.Skip("cannot create a FIFO:", err)
}
store := newFakeStore()
s, _ := newScanner(store, &fakeReader{}, 2)
type result struct {
sum Summary
err error
}
done := make(chan result, 1)
go func() {
sum, err := s.Scan(context.Background(), libsOf(root))
done <- result{sum, err}
}()
select {
case r := <-done:
if r.err != nil {
t.Fatal(r.err)
}
if r.sum.Found != 1 || r.sum.Added != 1 || r.sum.Skipped != 1 {
t.Fatalf("summary = %+v, want the FIFO skipped", r.sum)
}
case <-time.After(5 * time.Second):
t.Fatal("scan hung on a FIFO")
}
if store.row(root, "pipe.mp3") != nil {
t.Error("FIFO was indexed")
}
}