mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-06 05:16:38 +08:00
bug处理优化
bug处理优化
This commit is contained in:
@@ -27,3 +27,69 @@ func TestOrganizeTaskMetricsIncludesScrapeProcessed(t *testing.T) {
|
||||
t.Fatalf("scrape_skipped = %d, want 1", metrics["scrape_skipped"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCombineOrganizeItemsBuildsPerItemRows(t *testing.T) {
|
||||
res := &OrganizeResult{
|
||||
Items: []OrganizePreviewItem{
|
||||
{Source: `/downloads/Show.S01E01.mkv`, Target: `/media/Show/Show.S01E01.mkv`, Action: "organize", Title: "Show"},
|
||||
{Source: `/downloads/dup.mkv`, Action: "skip", Reason: "duplicate in library"},
|
||||
{Source: `/downloads/broken.mp4`, Action: "error", Reason: "unsupported codec"},
|
||||
},
|
||||
Scans: []OrganizeScanSummary{
|
||||
{LibraryID: "lib1", Name: "电影库"},
|
||||
{LibraryID: "lib2", Name: "剧集库", Error: "scan failed"},
|
||||
},
|
||||
Scrapes: []OrganizeScrapeSummary{
|
||||
{LibraryID: "lib1", Name: "电影库", Matched: 2},
|
||||
{LibraryID: "lib2", Name: "剧集库", Error: "scrape failed"},
|
||||
},
|
||||
}
|
||||
|
||||
items := combineOrganizeItems(res)
|
||||
if len(items) != 7 {
|
||||
t.Fatalf("len(items) = %d, want 7", len(items))
|
||||
}
|
||||
|
||||
// organize items mapped by source path.
|
||||
bySource := map[string]TaskItemRecord{}
|
||||
for _, item := range items {
|
||||
if item.Kind == ItemKindOrganize {
|
||||
bySource[item.Source] = item
|
||||
}
|
||||
}
|
||||
if got := bySource["/downloads/Show.S01E01.mkv"]; got.Status != ItemStatusSucceeded || got.Kind != ItemKindOrganize {
|
||||
t.Fatalf("organized item = %#v, want succeeded/organize", got)
|
||||
}
|
||||
if got := bySource["/downloads/broken.mp4"]; got.Status != ItemStatusFailed || got.Error == "" {
|
||||
t.Fatalf("error item = %#v, want failed with error", got)
|
||||
}
|
||||
if got := bySource["/downloads/dup.mkv"]; got.Status != ItemStatusSucceeded {
|
||||
t.Fatalf("skip item = %#v, want succeeded", got)
|
||||
}
|
||||
|
||||
// scan + scrape items carry library IDs.
|
||||
var scanFailed, scrapeFailed bool
|
||||
for _, item := range items {
|
||||
if item.Kind == ItemKindScan && item.LibraryID == "lib2" {
|
||||
scanFailed = item.Status == ItemStatusFailed
|
||||
}
|
||||
if item.Kind == ItemKindScrape && item.LibraryID == "lib2" {
|
||||
scrapeFailed = item.Status == ItemStatusFailed
|
||||
}
|
||||
}
|
||||
if !scanFailed {
|
||||
t.Fatal("scan lib2 should be failed")
|
||||
}
|
||||
if !scrapeFailed {
|
||||
t.Fatal("scrape lib2 should be failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCombineOrganizeItemsHandlesNoItems(t *testing.T) {
|
||||
if got := combineOrganizeItems(nil); got != nil {
|
||||
t.Fatalf("combineOrganizeItems(nil) = %#v, want nil", got)
|
||||
}
|
||||
if got := combineOrganizeItems(&OrganizeResult{}); got != nil {
|
||||
t.Fatalf("combineOrganizeItems(empty) = %#v, want nil", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user