Fixed tests with sqlite
continuous-integration/drone/pr Build is running Details
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kolaente 2019-03-29 18:15:54 +01:00
parent 93745865cd
commit 60e983c529
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 10 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import (
"fmt"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
"github.com/spf13/viper"
"gopkg.in/testfixtures.v2"
"os"
"path/filepath"
@ -52,6 +53,7 @@ func MainTest(m *testing.M, pathToRoot string) {
func createTestEngine(fixturesDir string) error {
var err error
var fixturesHelper testfixtures.Helper
fixturesHelper = &testfixtures.SQLite{}
// If set, use the config we provided instead of normal
if os.Getenv("VIKUNJA_TESTS_USE_CONFIG") == "1" {
config.InitConfig()
@ -60,7 +62,14 @@ func createTestEngine(fixturesDir string) error {
return err
}
fixturesHelper = &testfixtures.MySQL{}
err = x.Sync2(GetTables()...)
if err != nil {
return err
}
if viper.GetString("database.type") == "mysql" {
fixturesHelper = &testfixtures.MySQL{}
}
} else {
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
if err != nil {
@ -78,8 +87,6 @@ func createTestEngine(fixturesDir string) error {
if os.Getenv("UNIT_TESTS_VERBOSE") == "1" {
x.ShowSQL(true)
}
fixturesHelper = &testfixtures.SQLite{}
}
return InitFixtures(fixturesHelper, fixturesDir)