72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package ingest
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"mediarr/document"
|
|
)
|
|
|
|
func TestKindForFile(t *testing.T) {
|
|
cases := map[string]string{
|
|
"film.mkv": document.KindVideo,
|
|
"film.MP4": document.KindVideo,
|
|
"episode.srt": document.KindSubtitle,
|
|
"poster.JPG": document.KindImage,
|
|
"notes.txt": document.KindFile,
|
|
"sans-extension": document.KindFile,
|
|
"archive.tar.gz": document.KindFile,
|
|
}
|
|
for name, expected := range cases {
|
|
if kind := KindForFile(name); kind != expected {
|
|
t.Fatalf("KindForFile(%q) = %q, attendu %q", name, kind, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBasicProber(t *testing.T) {
|
|
t.Chdir(t.TempDir())
|
|
path := filepath.Join("film.mkv")
|
|
if err := os.WriteFile(path, []byte("x"), 0o644); err != nil {
|
|
t.Fatalf("WriteFile : %v", err)
|
|
}
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
t.Fatalf("Stat : %v", err)
|
|
}
|
|
|
|
probe, err := BasicProber{}.Probe(context.Background(), path, info)
|
|
if err != nil {
|
|
t.Fatalf("Probe : %v", err)
|
|
}
|
|
if probe.Mime == "" {
|
|
t.Fatal("mime vide")
|
|
}
|
|
}
|
|
|
|
func TestMetadataJSONPreservesExistingFields(t *testing.T) {
|
|
metadata, err := metadataJSON(`{"genre":"drame","size":1}`, map[string]any{
|
|
"source_path": "film.mkv",
|
|
"size": int64(2),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("metadataJSON : %v", err)
|
|
}
|
|
if metadata != `{"genre":"drame","size":2,"source_path":"film.mkv"}` {
|
|
t.Fatalf("metadata = %q", metadata)
|
|
}
|
|
|
|
if _, err := metadataJSON(`{`, map[string]any{"x": 1}); err == nil {
|
|
t.Fatal("metadataJSON avec JSON invalide : erreur attendue")
|
|
}
|
|
}
|
|
|
|
func TestScanRequiresServices(t *testing.T) {
|
|
var service *Service
|
|
if _, err := service.Scan(context.Background(), [16]byte{}, [16]byte{}, "."); err != ErrServiceNotConfigured {
|
|
t.Fatalf("erreur = %v, attendu ErrServiceNotConfigured", err)
|
|
}
|
|
}
|