fix: persistence tests were not being properly initialized

This commit is contained in:
Deluan 2020-01-26 17:10:13 -05:00
parent 7c2728aadc
commit 0ff741b394
3 changed files with 20 additions and 28 deletions

View File

@ -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 {

View File

@ -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())
})
})

View File

@ -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)
}
})
}