update
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled

This commit is contained in:
2025-12-08 16:16:23 +01:00
commit c251f174ed
1349 changed files with 194301 additions and 0 deletions

119
model/folder_test.go Normal file
View File

@@ -0,0 +1,119 @@
package model_test
import (
"path"
"path/filepath"
"time"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/id"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Folder", func() {
var (
lib model.Library
)
BeforeEach(func() {
lib = model.Library{
ID: 1,
Path: filepath.FromSlash("/music"),
}
})
Describe("FolderID", func() {
When("the folder path is the library root", func() {
It("should return the correct folder ID", func() {
folderPath := lib.Path
expectedID := id.NewHash("1:.")
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
})
})
When("the folder path is '.' (library root)", func() {
It("should return the correct folder ID", func() {
folderPath := "."
expectedID := id.NewHash("1:.")
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
})
})
When("the folder path is relative", func() {
It("should return the correct folder ID", func() {
folderPath := "rock"
expectedID := id.NewHash("1:rock")
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
})
})
When("the folder path starts with '.'", func() {
It("should return the correct folder ID", func() {
folderPath := "./rock"
expectedID := id.NewHash("1:rock")
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
})
})
When("the folder path is absolute", func() {
It("should return the correct folder ID", func() {
folderPath := filepath.FromSlash("/music/rock")
expectedID := id.NewHash("1:rock")
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
})
})
When("the folder has multiple subdirs", func() {
It("should return the correct folder ID", func() {
folderPath := filepath.FromSlash("/music/rock/metal")
expectedID := id.NewHash("1:rock/metal")
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
})
})
})
Describe("NewFolder", func() {
It("should create a new SubFolder with the correct attributes", func() {
folderPath := filepath.FromSlash("rock/metal")
folder := model.NewFolder(lib, folderPath)
Expect(folder.LibraryID).To(Equal(lib.ID))
Expect(folder.ID).To(Equal(model.FolderID(lib, folderPath)))
Expect(folder.Path).To(Equal(path.Clean("rock")))
Expect(folder.Name).To(Equal("metal"))
Expect(folder.ParentID).To(Equal(model.FolderID(lib, "rock")))
Expect(folder.ImageFiles).To(BeEmpty())
Expect(folder.UpdateAt).To(BeTemporally("~", time.Now(), time.Second))
Expect(folder.CreatedAt).To(BeTemporally("~", time.Now(), time.Second))
})
It("should create a new Folder with the correct attributes", func() {
folderPath := "rock"
folder := model.NewFolder(lib, folderPath)
Expect(folder.LibraryID).To(Equal(lib.ID))
Expect(folder.ID).To(Equal(model.FolderID(lib, folderPath)))
Expect(folder.Path).To(Equal(path.Clean(".")))
Expect(folder.Name).To(Equal("rock"))
Expect(folder.ParentID).To(Equal(model.FolderID(lib, ".")))
Expect(folder.ImageFiles).To(BeEmpty())
Expect(folder.UpdateAt).To(BeTemporally("~", time.Now(), time.Second))
Expect(folder.CreatedAt).To(BeTemporally("~", time.Now(), time.Second))
})
It("should handle the root folder correctly", func() {
folderPath := "."
folder := model.NewFolder(lib, folderPath)
Expect(folder.LibraryID).To(Equal(lib.ID))
Expect(folder.ID).To(Equal(model.FolderID(lib, folderPath)))
Expect(folder.Path).To(Equal(""))
Expect(folder.Name).To(Equal("."))
Expect(folder.ParentID).To(Equal(""))
Expect(folder.ImageFiles).To(BeEmpty())
Expect(folder.UpdateAt).To(BeTemporally("~", time.Now(), time.Second))
Expect(folder.CreatedAt).To(BeTemporally("~", time.Now(), time.Second))
})
})
})