Skip to content

🎧 Your Personal Streaming Service

fix: persistence tests were not being properly initialized

Deluan0ff741b39421
diff --git a/persistence/persistence_suite_test.go b/persistence/persistence_suite_test.go
index 9a64c7e03..d4f50b7a1 100644
--- a/persistence/persistence_suite_test.go
+++ b/persistence/persistence_suite_test.go
@@ -9,11 +9,13 @@ import (
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
+ "github.com/deluan/navidrome/tests"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestPersistence(t *testing.T) {
+ tests.Init(t, true)
log.SetLevel(log.LevelCritical)
RegisterFailHandler(Fail)
RunSpecs(t, "Persistence Suite")
@@ -59,14 +61,14 @@ func P(path string) string {
var _ = Describe("Initialize test DB", func() {
BeforeSuite(func() {
- //log.SetLevel(log.LevelTrace)
- //conf.Server.DbPath, _ = ioutil.TempDir("", "navidrome_tests")
- //os.MkdirAll(conf.Server.DbPath, 0700)
conf.Server.DbPath = ":memory:"
ds := New()
artistRepo := ds.Artist()
for _, a := range testArtists {
- artistRepo.Put(&a)
+ err := artistRepo.Put(&a)
+ if err != nil {
+ panic(err)
+ }
}
albumRepository := ds.Album()
for _, a := range testAlbums {
diff --git a/scanner/scanner_suite_test.go b/scanner/scanner_suite_test.go
index 61ac52bde..1d0fb6849 100644
--- a/scanner/scanner_suite_test.go
+++ b/scanner/scanner_suite_test.go
@@ -2,11 +2,8 @@ package scanner
import (
"testing"
- "time"
- "github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log"
- "github.com/deluan/navidrome/persistence"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@@ -17,15 +14,3 @@ func xTestScanner(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Scanner Suite")
}
-
-var _ = XDescribe("TODO: REMOVE", func() {
- It("WORKS!", func() {
- conf.Server.DbPath = "./testDB"
- log.SetLevel(log.LevelDebug)
- ds := persistence.New()
-
- t := NewTagScanner("/Users/deluan/Music/iTunes/iTunes Media/Music", ds)
- //t := NewTagScanner("/Users/deluan/Development/navidrome/navidrome/tests/fixtures", ds)
- Expect(t.Scan(nil, time.Time{})).To(BeNil())
- })
-})
diff --git a/tests/init_tests.go b/tests/init_tests.go
index 74360c3c6..267bf574a 100644
--- a/tests/init_tests.go
+++ b/tests/init_tests.go
@@ -4,25 +4,30 @@ import (
"os"
"path/filepath"
"runtime"
+ "sync"
"testing"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log"
)
+var once sync.Once
+
func Init(t *testing.T, skipOnShort bool) {
if skipOnShort && testing.Short() {
t.Skip("skipping test in short mode.")
}
- _, file, _, _ := runtime.Caller(0)
- appPath, _ := filepath.Abs(filepath.Join(filepath.Dir(file), ".."))
- confPath, _ := filepath.Abs(filepath.Join(appPath, "tests", "navidrome-test.toml"))
+ once.Do(func() {
+ _, file, _, _ := runtime.Caller(0)
+ appPath, _ := filepath.Abs(filepath.Join(filepath.Dir(file), ".."))
+ confPath, _ := filepath.Abs(filepath.Join(appPath, "tests", "navidrome-test.toml"))
- os.Chdir(appPath)
- conf.LoadFromFile(confPath)
+ os.Chdir(appPath)
+ conf.LoadFromFile(confPath)
- noLog := os.Getenv("NOLOG")
- if noLog != "" {
- log.SetLevel(log.LevelError)
- }
+ noLog := os.Getenv("NOLOG")
+ if noLog != "" {
+ log.SetLevel(log.LevelError)
+ }
+ })
}