Change tests' db path to a temp folder

This commit is contained in:
Deluan
2020-01-11 16:47:26 -05:00
parent 4b1c909a4d
commit 6c05930444
2 changed files with 7 additions and 4 deletions
-3
View File
@@ -1,10 +1,8 @@
package db_storm package db_storm
import ( import (
"fmt"
"os" "os"
"path" "path"
"path/filepath"
"sync" "sync"
"github.com/asdine/storm" "github.com/asdine/storm"
@@ -24,7 +22,6 @@ func Db() *storm.DB {
panic(err) panic(err)
} }
dbPath := path.Join(conf.Sonic.DbPath, "storm.db") dbPath := path.Join(conf.Sonic.DbPath, "storm.db")
dbPath = fmt.Sprintf(".%c%s", filepath.Separator, dbPath)
instance, err := storm.Open(dbPath) instance, err := storm.Open(dbPath)
log.Debug("Opening Storm DB from: " + dbPath) log.Debug("Opening Storm DB from: " + dbPath)
if err != nil { if err != nil {
+7 -1
View File
@@ -1,15 +1,19 @@
package db_storm package db_storm
import ( import (
"io/ioutil"
"os"
"testing" "testing"
"github.com/cloudsonic/sonic-server/conf"
"github.com/cloudsonic/sonic-server/domain" "github.com/cloudsonic/sonic-server/domain"
"github.com/cloudsonic/sonic-server/log"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
func TestStormPersistence(t *testing.T) { func TestStormPersistence(t *testing.T) {
//log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelCritical)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Storm Persistence Suite") RunSpecs(t, "Storm Persistence Suite")
} }
@@ -27,6 +31,8 @@ var testArtists = domain.Artists{
var _ = Describe("Initialize test DB", func() { var _ = Describe("Initialize test DB", func() {
BeforeSuite(func() { BeforeSuite(func() {
conf.Sonic.DbPath, _ = ioutil.TempDir("", "cloudsonic_tests")
os.MkdirAll(conf.Sonic.DbPath, 0700)
Db().Drop(&_Album{}) Db().Drop(&_Album{})
albumRepo := NewAlbumRepository() albumRepo := NewAlbumRepository()
for _, a := range testAlbums { for _, a := range testAlbums {