mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-06 05:57:35 +03:00
Run SQL tests in memory
This commit is contained in:
parent
87ca885b5e
commit
4b08df0725
6 changed files with 20 additions and 16 deletions
|
@ -52,7 +52,7 @@ func (r *checkSumRepository) Get(id string) (string, error) {
|
|||
|
||||
func (r *checkSumRepository) SetData(newSums map[string]string) error {
|
||||
err := WithTx(func(o orm.Ormer) error {
|
||||
_, err := Db().Raw("delete from checksum").Exec()
|
||||
_, err := Db().QueryTable(&Checksum{}).Filter("id__isnull", false).Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -105,9 +105,4 @@ func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) DeleteAll() error {
|
||||
_, err := Db().Raw("delete from artist_info").Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
||||
|
|
|
@ -10,8 +10,8 @@ var _ = Describe("PropertyRepository", func() {
|
|||
var repo domain.PropertyRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
Db().Raw("delete from property").Exec()
|
||||
repo = NewPropertyRepository()
|
||||
repo.(*propertyRepository).DeleteAll()
|
||||
})
|
||||
|
||||
It("saves and retrieves data", func() {
|
||||
|
|
|
@ -15,12 +15,17 @@ var once sync.Once
|
|||
|
||||
func Db() orm.Ormer {
|
||||
once.Do(func() {
|
||||
dbPath := conf.Sonic.DbPath
|
||||
if dbPath == ":memory:" {
|
||||
dbPath = "file::memory:?cache=shared"
|
||||
} else {
|
||||
err := os.MkdirAll(conf.Sonic.DbPath, 0700)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dbPath := path.Join(conf.Sonic.DbPath, "sqlite.db")
|
||||
err = initORM(dbPath)
|
||||
dbPath = path.Join(conf.Sonic.DbPath, "sqlite.db")
|
||||
}
|
||||
err := initORM(dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -103,6 +103,11 @@ func difference(slice1 []string, slice2 []string) []string {
|
|||
return diffStr
|
||||
}
|
||||
|
||||
func (r *sqlRepository) DeleteAll() error {
|
||||
_, err := r.newQuery(Db()).Filter("id__isnull", false).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *sqlRepository) purgeInactive(activeList interface{}, getId func(item interface{}) string) ([]string, error) {
|
||||
allIds, err := r.GetAllIds()
|
||||
if err != nil {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package db_sql
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
|
@ -31,8 +29,9 @@ var testArtists = domain.Artists{
|
|||
|
||||
var _ = Describe("Initialize test DB", func() {
|
||||
BeforeSuite(func() {
|
||||
conf.Sonic.DbPath, _ = ioutil.TempDir("", "cloudsonic_tests")
|
||||
os.MkdirAll(conf.Sonic.DbPath, 0700)
|
||||
//conf.Sonic.DbPath, _ = ioutil.TempDir("", "cloudsonic_tests")
|
||||
//os.MkdirAll(conf.Sonic.DbPath, 0700)
|
||||
conf.Sonic.DbPath = ":memory:"
|
||||
Db()
|
||||
artistRepo := NewArtistRepository()
|
||||
for _, a := range testArtists {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue