mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-08 14:26:37 +08:00
fix emby clients and cloud playback controls
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/glebarez/sqlite"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/ShukeBta/MediaStationGo/internal/model"
|
||||
"github.com/ShukeBta/MediaStationGo/internal/repository"
|
||||
)
|
||||
|
||||
func TestWatcherRefreshMapsHostLibraryPathToContainerPath(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
hostMedia := filepath.Join(root, "nas-host", "media")
|
||||
containerMedia := filepath.Join(root, "container", "media")
|
||||
containerLibrary := filepath.Join(containerMedia, "电视剧", "国产剧")
|
||||
if err := os.MkdirAll(containerLibrary, 0o755); err != nil {
|
||||
t.Fatalf("mkdir container library: %v", err)
|
||||
}
|
||||
t.Setenv("MEDIASTATION_MEDIA_DIR", hostMedia)
|
||||
t.Setenv("MEDIASTATION_MEDIA_CONTAINER_DIR", containerMedia)
|
||||
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatalf("open db: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.Library{}); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
repos := repository.New(db)
|
||||
lib := model.Library{
|
||||
Base: model.Base{ID: "lib-tv"},
|
||||
Name: "国产剧",
|
||||
Path: filepath.Join(hostMedia, "电视剧", "国产剧"),
|
||||
Type: "tv",
|
||||
Enabled: true,
|
||||
}
|
||||
if err := repos.Library.Create(t.Context(), &lib); err != nil {
|
||||
t.Fatalf("create library: %v", err)
|
||||
}
|
||||
fw, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
t.Fatalf("new watcher: %v", err)
|
||||
}
|
||||
defer fw.Close()
|
||||
watcher := NewWatcherService(zap.NewNop(), repos, nil)
|
||||
watcher.watcher = fw
|
||||
|
||||
if err := watcher.Refresh(t.Context()); err != nil {
|
||||
t.Fatalf("refresh: %v", err)
|
||||
}
|
||||
if _, ok := watcher.watched[filepath.Clean(containerLibrary)]; !ok {
|
||||
t.Fatalf("expected mapped container path watched, got %#v", watcher.watched)
|
||||
}
|
||||
if _, ok := watcher.watched[filepath.Clean(lib.Path)]; ok {
|
||||
t.Fatalf("host path should not be watched inside container: %#v", watcher.watched)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user