test: use unique library name and path in tests
Avoid UNIQUE constraint conflicts on library.name and library.path when running tests in parallel. Both playlist_repository_test.go and tag_library_filtering_test.go now generate timestamp-based unique suffixes for library names and paths to ensure test isolation. Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -372,15 +372,18 @@ var _ = Describe("PlaylistRepository", func() {
|
|||||||
var testPlaylistID string
|
var testPlaylistID string
|
||||||
var lib2ID int
|
var lib2ID int
|
||||||
var restrictedUserID string
|
var restrictedUserID string
|
||||||
|
var uniqueLibPath string
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
db := GetDBXBuilder()
|
db := GetDBXBuilder()
|
||||||
|
|
||||||
// Generate unique IDs for this test run
|
// Generate unique IDs for this test run
|
||||||
restrictedUserID = "restricted-user-" + time.Now().Format("20060102150405.000")
|
uniqueSuffix := time.Now().Format("20060102150405.000")
|
||||||
|
restrictedUserID = "restricted-user-" + uniqueSuffix
|
||||||
|
uniqueLibPath = "/music/lib2-" + uniqueSuffix
|
||||||
|
|
||||||
// Create a second library
|
// Create a second library with unique name and path to avoid conflicts with other tests
|
||||||
_, err := db.DB().Exec("INSERT INTO library (name, path, created_at, updated_at) VALUES ('Library 2', '/music/lib2', datetime('now'), datetime('now'))")
|
_, err := db.DB().Exec("INSERT INTO library (name, path, created_at, updated_at) VALUES (?, ?, datetime('now'), datetime('now'))", "Library 2-"+uniqueSuffix, uniqueLibPath)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
err = db.DB().QueryRow("SELECT last_insert_rowid()").Scan(&lib2ID)
|
err = db.DB().QueryRow("SELECT last_insert_rowid()").Scan(&lib2ID)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -420,7 +423,7 @@ var _ = Describe("PlaylistRepository", func() {
|
|||||||
ArtistID: "1",
|
ArtistID: "1",
|
||||||
Album: "Test Album",
|
Album: "Test Album",
|
||||||
AlbumID: "101",
|
AlbumID: "101",
|
||||||
Path: "/music/lib2/song.mp3",
|
Path: uniqueLibPath + "/song.mp3",
|
||||||
LibraryID: lib2ID,
|
LibraryID: lib2ID,
|
||||||
Participants: model.Participants{},
|
Participants: model.Participants{},
|
||||||
Tags: model.Tags{},
|
Tags: model.Tags{},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/deluan/rest"
|
"github.com/deluan/rest"
|
||||||
"github.com/navidrome/navidrome/conf/configtest"
|
"github.com/navidrome/navidrome/conf/configtest"
|
||||||
@@ -45,6 +46,9 @@ var _ = Describe("Tag Library Filtering", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
DeferCleanup(configtest.SetupConfig())
|
DeferCleanup(configtest.SetupConfig())
|
||||||
|
|
||||||
|
// Generate unique path suffix to avoid conflicts with other tests
|
||||||
|
uniqueSuffix := time.Now().Format("20060102150405.000")
|
||||||
|
|
||||||
// Clean up database
|
// Clean up database
|
||||||
db := GetDBXBuilder()
|
db := GetDBXBuilder()
|
||||||
_, err := db.NewQuery("DELETE FROM library_tag").Execute()
|
_, err := db.NewQuery("DELETE FROM library_tag").Execute()
|
||||||
@@ -57,12 +61,12 @@ var _ = Describe("Tag Library Filtering", func() {
|
|||||||
_, err = db.NewQuery("DELETE FROM library WHERE id > 1").Execute()
|
_, err = db.NewQuery("DELETE FROM library WHERE id > 1").Execute()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
// Create test libraries
|
// Create test libraries with unique names and paths to avoid conflicts with other tests
|
||||||
_, err = db.NewQuery("INSERT INTO library (id, name, path) VALUES ({:id}, {:name}, {:path})").
|
_, err = db.NewQuery("INSERT INTO library (id, name, path) VALUES ({:id}, {:name}, {:path})").
|
||||||
Bind(dbx.Params{"id": libraryID2, "name": "Library 2", "path": "/music/lib2"}).Execute()
|
Bind(dbx.Params{"id": libraryID2, "name": "Library 2-" + uniqueSuffix, "path": "/music/lib2-" + uniqueSuffix}).Execute()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
_, err = db.NewQuery("INSERT INTO library (id, name, path) VALUES ({:id}, {:name}, {:path})").
|
_, err = db.NewQuery("INSERT INTO library (id, name, path) VALUES ({:id}, {:name}, {:path})").
|
||||||
Bind(dbx.Params{"id": libraryID3, "name": "Library 3", "path": "/music/lib3"}).Execute()
|
Bind(dbx.Params{"id": libraryID3, "name": "Library 3-" + uniqueSuffix, "path": "/music/lib3-" + uniqueSuffix}).Execute()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
// Give admin access to all libraries
|
// Give admin access to all libraries
|
||||||
|
|||||||
Reference in New Issue
Block a user