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
90 lines
3.1 KiB
Go
90 lines
3.1 KiB
Go
package model_test
|
|
|
|
import (
|
|
"github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("ParseTargets", func() {
|
|
It("parses multiple entries in slice", func() {
|
|
targets, err := model.ParseTargets([]string{"1:Music/Rock", "1:Music/Jazz", "2:Classical"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(targets).To(HaveLen(3))
|
|
Expect(targets[0].LibraryID).To(Equal(1))
|
|
Expect(targets[0].FolderPath).To(Equal("Music/Rock"))
|
|
Expect(targets[1].LibraryID).To(Equal(1))
|
|
Expect(targets[1].FolderPath).To(Equal("Music/Jazz"))
|
|
Expect(targets[2].LibraryID).To(Equal(2))
|
|
Expect(targets[2].FolderPath).To(Equal("Classical"))
|
|
})
|
|
|
|
It("handles empty folder paths", func() {
|
|
targets, err := model.ParseTargets([]string{"1:", "2:"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(targets).To(HaveLen(2))
|
|
Expect(targets[0].FolderPath).To(Equal(""))
|
|
Expect(targets[1].FolderPath).To(Equal(""))
|
|
})
|
|
|
|
It("trims whitespace from entries", func() {
|
|
targets, err := model.ParseTargets([]string{" 1:Music/Rock", " 2:Classical "})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(targets).To(HaveLen(2))
|
|
Expect(targets[0].LibraryID).To(Equal(1))
|
|
Expect(targets[0].FolderPath).To(Equal("Music/Rock"))
|
|
Expect(targets[1].LibraryID).To(Equal(2))
|
|
Expect(targets[1].FolderPath).To(Equal("Classical"))
|
|
})
|
|
|
|
It("skips empty strings", func() {
|
|
targets, err := model.ParseTargets([]string{"1:Music/Rock", "", "2:Classical"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(targets).To(HaveLen(2))
|
|
})
|
|
|
|
It("handles paths with colons", func() {
|
|
targets, err := model.ParseTargets([]string{"1:C:/Music/Rock", "2:/path:with:colons"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(targets).To(HaveLen(2))
|
|
Expect(targets[0].FolderPath).To(Equal("C:/Music/Rock"))
|
|
Expect(targets[1].FolderPath).To(Equal("/path:with:colons"))
|
|
})
|
|
|
|
It("returns error for invalid format without colon", func() {
|
|
_, err := model.ParseTargets([]string{"1Music/Rock"})
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("invalid target format"))
|
|
})
|
|
|
|
It("returns error for non-numeric library ID", func() {
|
|
_, err := model.ParseTargets([]string{"abc:Music/Rock"})
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("invalid library ID"))
|
|
})
|
|
|
|
It("returns error for negative library ID", func() {
|
|
_, err := model.ParseTargets([]string{"-1:Music/Rock"})
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("invalid library ID"))
|
|
})
|
|
|
|
It("returns error for zero library ID", func() {
|
|
_, err := model.ParseTargets([]string{"0:Music/Rock"})
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("invalid library ID"))
|
|
})
|
|
|
|
It("returns error for empty input", func() {
|
|
_, err := model.ParseTargets([]string{})
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("no valid targets found"))
|
|
})
|
|
|
|
It("returns error for all empty strings", func() {
|
|
_, err := model.ParseTargets([]string{"", " ", ""})
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("no valid targets found"))
|
|
})
|
|
})
|