diff options
author | techknowlogick <techknowlogick@gitea.io> | 2020-06-17 15:07:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-17 22:07:58 +0300 |
commit | 9e6a79bea9d7911c81b86a6d3715d340fc19032a (patch) | |
tree | 3c5982227a3ed7481786185f5fdf5a8c1107f279 /models/test_fixtures.go | |
parent | 1645d4a5d8def3cc5451e068aa0a321e028a889b (diff) | |
download | gitea-9e6a79bea9d7911c81b86a6d3715d340fc19032a.tar.gz gitea-9e6a79bea9d7911c81b86a6d3715d340fc19032a.zip |
upgrade to use testfixtures v3 (#11904)
* upgrade to use testfixtures v3
* simplify logic
* make vendor
* update per @lunny
* Update templates/repo/empty.tmpl
* Update templates/repo/empty.tmpl
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/test_fixtures.go')
-rw-r--r-- | models/test_fixtures.go | 40 |
1 files changed, 35 insertions, 5 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 } |