sonda/internal/streaming/fifo_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

52 lines
1.2 KiB
Go

//go:build unix
package streaming
import (
"context"
"errors"
"os"
"path/filepath"
"syscall"
"testing"
"time"
)
// Opening a named pipe blocks forever until a writer shows up, so a FIFO must
// be refused without ever blocking the request.
func TestOpenRefusesFIFOsWithoutHanging(t *testing.T) {
root := t.TempDir()
if err := syscall.Mkfifo(filepath.Join(root, "pipe.mp3"), 0o644); err != nil {
t.Skip("cannot create a FIFO:", err)
}
if err := os.Symlink("pipe.mp3", filepath.Join(root, "pipelink.mp3")); err != nil {
t.Skip("symlinks not supported:", err)
}
for _, rel := range []string{"pipe.mp3", "pipelink.mp3"} {
s := service(map[int64]File{1: {Root: root, RelPath: rel}})
type result struct {
st *Stream
err error
}
done := make(chan result, 1)
go func() {
st, err := s.Open(context.Background(), 1)
done <- result{st, err}
}()
select {
case r := <-done:
if r.err == nil {
r.st.Close()
t.Fatalf("%s: a FIFO was opened as a stream", rel)
}
if !errors.Is(r.err, ErrUnsafePath) {
t.Errorf("%s: err = %v, want ErrUnsafePath", rel, r.err)
}
case <-time.After(3 * time.Second):
t.Fatalf("%s: Open blocked on a FIFO", rel)
}
}
}