diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/test_fixtures.go | 40 | ||||
-rw-r--r-- | models/unit_tests.go | 3 |
2 files changed, 36 insertions, 7 deletions
diff --git a/models/test_fixtures.go b/models/test_fixtures.go index 6c160742bd..5cca7c16e8 100644 --- a/models/test_fixtures.go +++ b/models/test_fixtures.go @@ -6,18 +6,48 @@ package models import ( "fmt" + "os" "time" - "gopkg.in/testfixtures.v2" + "github.com/go-testfixtures/testfixtures/v3" "xorm.io/xorm/schemas" ) -var fixtures *testfixtures.Context +var fixtures *testfixtures.Loader // InitFixtures initialize test fixtures for a test database -func InitFixtures(helper testfixtures.Helper, dir string) (err error) { - testfixtures.SkipDatabaseNameCheck(true) - fixtures, err = testfixtures.NewFolder(x.DB().DB, helper, dir) +func InitFixtures(dir string) (err error) { + testfiles := testfixtures.Directory(dir) + dialect := "unknown" + switch x.Dialect().URI().DBType { + case schemas.POSTGRES: + dialect = "postgres" + case schemas.MYSQL: + dialect = "mysql" + case schemas.MSSQL: + dialect = "mssql" + case schemas.SQLITE: + dialect = "sqlite3" + default: + fmt.Println("Unsupported RDBMS for integration tests") + os.Exit(1) + } + loaderOptions := []func(loader *testfixtures.Loader) error{ + testfixtures.Database(x.DB().DB), + testfixtures.Dialect(dialect), + testfixtures.DangerousSkipTestDatabaseCheck(), + testfiles, + } + + if x.Dialect().URI().DBType == schemas.POSTGRES { + loaderOptions = append(loaderOptions, testfixtures.SkipResetSequences()) + } + + fixtures, err = testfixtures.New(loaderOptions...) + if err != nil { + return err + } + return err } diff --git a/models/unit_tests.go b/models/unit_tests.go index 1b27eebcd0..9266b3a658 100644 --- a/models/unit_tests.go +++ b/models/unit_tests.go @@ -19,7 +19,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/unknwon/com" - "gopkg.in/testfixtures.v2" "xorm.io/xorm" "xorm.io/xorm/names" ) @@ -101,7 +100,7 @@ func CreateTestEngine(fixturesDir string) error { x.ShowSQL(true) } - return InitFixtures(&testfixtures.SQLite{}, fixturesDir) + return InitFixtures(fixturesDir) } func removeAllWithRetry(dir string) error { |