Run SQL tests in memory
This commit is contained in:
@@ -52,7 +52,7 @@ func (r *checkSumRepository) Get(id string) (string, error) {
|
|||||||
|
|
||||||
func (r *checkSumRepository) SetData(newSums map[string]string) error {
|
func (r *checkSumRepository) SetData(newSums map[string]string) error {
|
||||||
err := WithTx(func(o orm.Ormer) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,4 @@ func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *artistIndexRepository) DeleteAll() error {
|
|
||||||
_, err := Db().Raw("delete from artist_info").Exec()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ var _ = Describe("PropertyRepository", func() {
|
|||||||
var repo domain.PropertyRepository
|
var repo domain.PropertyRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
Db().Raw("delete from property").Exec()
|
|
||||||
repo = NewPropertyRepository()
|
repo = NewPropertyRepository()
|
||||||
|
repo.(*propertyRepository).DeleteAll()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("saves and retrieves data", func() {
|
It("saves and retrieves data", func() {
|
||||||
|
|||||||
@@ -15,12 +15,17 @@ var once sync.Once
|
|||||||
|
|
||||||
func Db() orm.Ormer {
|
func Db() orm.Ormer {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
err := os.MkdirAll(conf.Sonic.DbPath, 0700)
|
dbPath := conf.Sonic.DbPath
|
||||||
if err != nil {
|
if dbPath == ":memory:" {
|
||||||
panic(err)
|
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")
|
||||||
}
|
}
|
||||||
dbPath := path.Join(conf.Sonic.DbPath, "sqlite.db")
|
err := initORM(dbPath)
|
||||||
err = initORM(dbPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ func difference(slice1 []string, slice2 []string) []string {
|
|||||||
return diffStr
|
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) {
|
func (r *sqlRepository) purgeInactive(activeList interface{}, getId func(item interface{}) string) ([]string, error) {
|
||||||
allIds, err := r.GetAllIds()
|
allIds, err := r.GetAllIds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package db_sql
|
package db_sql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/cloudsonic/sonic-server/conf"
|
"github.com/cloudsonic/sonic-server/conf"
|
||||||
@@ -31,8 +29,9 @@ 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")
|
//conf.Sonic.DbPath, _ = ioutil.TempDir("", "cloudsonic_tests")
|
||||||
os.MkdirAll(conf.Sonic.DbPath, 0700)
|
//os.MkdirAll(conf.Sonic.DbPath, 0700)
|
||||||
|
conf.Sonic.DbPath = ":memory:"
|
||||||
Db()
|
Db()
|
||||||
artistRepo := NewArtistRepository()
|
artistRepo := NewArtistRepository()
|
||||||
for _, a := range testArtists {
|
for _, a := range testArtists {
|
||||||
|
|||||||
Reference in New Issue
Block a user