mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-11 07:46:37 +08:00
Fix organize targets and cloud transfer controls
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
func TestStorageConfigLogoutClearsCloudCredentialsOnly(t *testing.T) {
|
||||
_, storage := newStorageUploadTestService(t)
|
||||
"github.com/ShukeBta/MediaStationGo/internal/model"
|
||||
)
|
||||
|
||||
func TestStorageConfigLogoutClearsCredentialsAndCloudLibraries(t *testing.T) {
|
||||
repos, storage := newStorageUploadTestService(t)
|
||||
enabled := true
|
||||
if _, err := storage.Save(t.Context(), StorageInput{
|
||||
Type: "openlist",
|
||||
@@ -20,6 +24,20 @@ func TestStorageConfigLogoutClearsCloudCredentialsOnly(t *testing.T) {
|
||||
}); err != nil {
|
||||
t.Fatalf("save storage: %v", err)
|
||||
}
|
||||
cloudLib := model.Library{Name: "OpenList", Path: BuildCloudLibraryPath("openlist", "/TV", "/TV"), Type: "tv", Enabled: true}
|
||||
if err := repos.Library.Create(t.Context(), &cloudLib); err != nil {
|
||||
t.Fatalf("create cloud library: %v", err)
|
||||
}
|
||||
localLib := model.Library{Name: "Local", Path: t.TempDir(), Type: "movie", Enabled: true}
|
||||
if err := repos.Library.Create(t.Context(), &localLib); err != nil {
|
||||
t.Fatalf("create local library: %v", err)
|
||||
}
|
||||
if err := repos.Media.Upsert(t.Context(), &model.Media{LibraryID: cloudLib.ID, Title: "Cloud", Path: "cloud://openlist/TV/Movie.mkv"}); err != nil {
|
||||
t.Fatalf("create cloud media: %v", err)
|
||||
}
|
||||
if err := repos.Media.Upsert(t.Context(), &model.Media{LibraryID: localLib.ID, Title: "Local", Path: localLib.Path + "/Movie.mkv"}); err != nil {
|
||||
t.Fatalf("create local media: %v", err)
|
||||
}
|
||||
|
||||
view, err := storage.Logout(t.Context(), "openlist")
|
||||
if err != nil {
|
||||
@@ -36,4 +54,21 @@ func TestStorageConfigLogoutClearsCloudCredentialsOnly(t *testing.T) {
|
||||
if view.Config["server"] != "http://openlist.test" || view.Config["url"] != "http://openlist.test/dav/" || view.Config["timeout_seconds"] != "120" {
|
||||
t.Fatalf("logout should keep non-secret connection hints, config = %#v", view.Config)
|
||||
}
|
||||
if got, err := repos.Library.FindByID(t.Context(), cloudLib.ID); err != nil {
|
||||
t.Fatalf("find cloud library: %v", err)
|
||||
} else if got != nil {
|
||||
t.Fatalf("cloud library should be removed after logout: %#v", got)
|
||||
}
|
||||
if got, err := repos.Library.FindByID(t.Context(), localLib.ID); err != nil {
|
||||
t.Fatalf("find local library: %v", err)
|
||||
} else if got == nil {
|
||||
t.Fatal("local library should remain after cloud logout")
|
||||
}
|
||||
var cloudMediaCount int64
|
||||
if err := repos.DB.Unscoped().Model(&model.Media{}).Where("path = ?", "cloud://openlist/TV/Movie.mkv").Count(&cloudMediaCount).Error; err != nil {
|
||||
t.Fatalf("count cloud media: %v", err)
|
||||
}
|
||||
if cloudMediaCount != 0 {
|
||||
t.Fatalf("cloud media should be purged after logout, count=%d", cloudMediaCount)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user