1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Move login related structs and functions to models/login (#17093)

* Move login related structs and functions to models/login

* Fix test

* Fix lint

* Fix lint

* Fix lint of windows

* Fix lint

* Fix test

* Fix test

* Only load necessary fixtures when preparing unit tests envs

* Fix lint

* Fix test

* Fix test

* Fix error log

* Fix error log

* Fix error log

* remove unnecessary change

* fix error log

* merge main branch
This commit is contained in:
Lunny Xiao
2021-09-24 19:32:56 +08:00
committed by GitHub
parent 4a2655098f
commit 5842a55b31
142 changed files with 1050 additions and 907 deletions

View File

@@ -44,11 +44,21 @@ func fatalTestError(fmtStr string, args ...interface{}) {
// MainTest a reusable TestMain(..) function for unit tests that need to use a
// test database. Creates the test database, and sets necessary settings.
func MainTest(m *testing.M, pathToGiteaRoot string) {
func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
var err error
giteaRoot = pathToGiteaRoot
fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
if err = CreateTestEngine(fixturesDir); err != nil {
var opts FixturesOptions
if len(fixtureFiles) == 0 {
opts.Dir = fixturesDir
} else {
for _, f := range fixtureFiles {
opts.Files = append(opts.Files, filepath.Join(fixturesDir, f))
}
}
if err = CreateTestEngine(opts); err != nil {
fatalTestError("Error creating test engine: %v\n", err)
}
@@ -102,8 +112,14 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
os.Exit(exitStatus)
}
// FixturesOptions fixtures needs to be loaded options
type FixturesOptions struct {
Dir string
Files []string
}
// CreateTestEngine creates a memory database and loads the fixture data from fixturesDir
func CreateTestEngine(fixturesDir string) error {
func CreateTestEngine(opts FixturesOptions) error {
var err error
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared&_txlock=immediate")
if err != nil {
@@ -123,7 +139,7 @@ func CreateTestEngine(fixturesDir string) error {
e: x,
}
return InitFixtures(fixturesDir)
return InitFixtures(opts)
}
// PrepareTestDatabase load test fixtures into test database