Files
MeBox/internal/service/scanner_library_roots_test.go
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* Rebrand MMTL to MeBox across codebase and assets

Rename the project display name, Go module path, environment variable
prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl
to MeBox/mebox. Replace logo assets with the new MeBox icon and keep
legacy SQLite migration support for existing mmtl.db deployments.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* Fix logo icons: use cube-only crop without truncated text

Previous icon generation cropped too much of the source image, including
partial MeBox wordmark text that was cut off in square icon containers.
Regenerate logo-64/192/512, favicon, and SVG from cube-only region.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
2026-09-02 16:26:28 +08:00

91 lines
2.4 KiB
Go

package service
import (
"os"
"path/filepath"
"testing"
"go.uber.org/zap"
"github.com/truewhile/MeBox/internal/model"
"github.com/truewhile/MeBox/internal/repository"
)
func TestScanLibraryScansMultipleRootsAndPrunesPerRoot(t *testing.T) {
rootA := t.TempDir()
rootB := t.TempDir()
fileA := filepath.Join(rootA, "电影A.2024.mkv")
fileB := filepath.Join(rootB, "电影B.2025.mkv")
writeTestFile(t, fileA, "a")
writeTestFile(t, fileB, "b")
db := newServiceTestDB(t, &model.Library{}, &model.LibraryRoot{}, &model.Media{}, &model.Setting{})
repos := repository.New(db)
lib := &model.Library{Name: "电影", Path: rootA, Type: "movie", Enabled: true}
roots := []model.LibraryRoot{
{Name: "硬盘1", Path: rootA, Enabled: true, SortOrder: 0},
{Name: "硬盘2", Path: rootB, Enabled: true, SortOrder: 1},
}
if err := repos.Library.CreateWithRoots(t.Context(), lib, roots); err != nil {
t.Fatal(err)
}
scanner := NewScannerService(nil, zap.NewNop(), repos, NewHub(zap.NewNop()), nil, nil)
res, err := scanner.ScanLibrary(t.Context(), lib.ID)
if err != nil {
t.Fatalf("scan multiple roots: %v", err)
}
if res.Added != 2 {
t.Fatalf("added = %d, want 2", res.Added)
}
var rows []model.Media
if err := db.Order("path asc").Find(&rows).Error; err != nil {
t.Fatal(err)
}
if len(rows) != 2 {
t.Fatalf("media rows = %d, want 2", len(rows))
}
for _, row := range rows {
if row.LibraryRootID == "" {
t.Fatalf("media %q missing library_root_id", row.Path)
}
if row.RelativePath == "" {
t.Fatalf("media %q missing relative_path", row.Path)
}
}
removeTestPath(t, fileA)
removeTestPath(t, rootB)
res, err = scanner.ScanLibrary(t.Context(), lib.ID)
if err != nil {
t.Fatalf("scan with one offline root should continue: %v", err)
}
if res.Removed != 1 {
t.Fatalf("removed = %d, want only vanished file from accessible root removed", res.Removed)
}
rows = nil
if err := db.Find(&rows).Error; err != nil {
t.Fatal(err)
}
if len(rows) != 1 || rows[0].Path != fileB {
t.Fatalf("remaining rows = %#v, want offline root media preserved", rows)
}
}
func writeTestFile(t *testing.T, path, content string) {
t.Helper()
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
t.Fatal(err)
}
}
func removeTestPath(t *testing.T, path string) {
t.Helper()
if err := os.RemoveAll(path); err != nil {
t.Fatal(err)
}
}