summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/asymkey/main_test.go6
-rw-r--r--models/dbfs/main_test.go6
-rw-r--r--models/issues/main_test.go6
-rw-r--r--models/main_test.go6
-rw-r--r--models/migrations/base/tests.go2
-rw-r--r--models/unittest/testdb.go22
6 files changed, 23 insertions, 25 deletions
diff --git a/models/asymkey/main_test.go b/models/asymkey/main_test.go
index 7f8657189f..701722be12 100644
--- a/models/asymkey/main_test.go
+++ b/models/asymkey/main_test.go
@@ -8,14 +8,8 @@ import (
"testing"
"code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/setting"
)
-func init() {
- setting.SetCustomPathAndConf("", "", "")
- setting.InitProviderAndLoadCommonSettingsForTest()
-}
-
func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
diff --git a/models/dbfs/main_test.go b/models/dbfs/main_test.go
index 9dce663eea..62db3592be 100644
--- a/models/dbfs/main_test.go
+++ b/models/dbfs/main_test.go
@@ -8,14 +8,8 @@ import (
"testing"
"code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/setting"
)
-func init() {
- setting.SetCustomPathAndConf("", "", "")
- setting.InitProviderAndLoadCommonSettingsForTest()
-}
-
func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
diff --git a/models/issues/main_test.go b/models/issues/main_test.go
index de84da30ec..9fbe294f70 100644
--- a/models/issues/main_test.go
+++ b/models/issues/main_test.go
@@ -9,7 +9,6 @@ import (
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/setting"
_ "code.gitea.io/gitea/models"
_ "code.gitea.io/gitea/models/repo"
@@ -18,11 +17,6 @@ import (
"github.com/stretchr/testify/assert"
)
-func init() {
- setting.SetCustomPathAndConf("", "", "")
- setting.InitProviderAndLoadCommonSettingsForTest()
-}
-
func TestFixturesAreConsistent(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
unittest.CheckConsistencyFor(t,
diff --git a/models/main_test.go b/models/main_test.go
index b5919bb286..d490507649 100644
--- a/models/main_test.go
+++ b/models/main_test.go
@@ -11,18 +11,12 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/setting"
_ "code.gitea.io/gitea/models/system"
"github.com/stretchr/testify/assert"
)
-func init() {
- setting.SetCustomPathAndConf("", "", "")
- setting.InitProviderAndLoadCommonSettingsForTest()
-}
-
// TestFixturesAreConsistent assert that test fixtures are consistent
func TestFixturesAreConsistent(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
diff --git a/models/migrations/base/tests.go b/models/migrations/base/tests.go
index 14f374f1a7..124111f51f 100644
--- a/models/migrations/base/tests.go
+++ b/models/migrations/base/tests.go
@@ -150,7 +150,7 @@ func MainTest(m *testing.M) {
setting.AppDataPath = tmpDataPath
setting.SetCustomPathAndConf("", "", "")
- setting.InitProviderAndLoadCommonSettingsForTest()
+ unittest.InitSettings()
if err = git.InitFull(context.Background()); err != nil {
fmt.Printf("Unable to InitFull: %v\n", err)
os.Exit(1)
diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go
index cff1489a7c..a5b126350d 100644
--- a/models/unittest/testdb.go
+++ b/models/unittest/testdb.go
@@ -6,12 +6,15 @@ package unittest
import (
"context"
"fmt"
+ "log"
"os"
"path/filepath"
+ "strings"
"testing"
"code.gitea.io/gitea/models/db"
system_model "code.gitea.io/gitea/models/system"
+ "code.gitea.io/gitea/modules/auth/password/hash"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
@@ -39,6 +42,22 @@ func fatalTestError(fmtStr string, args ...interface{}) {
os.Exit(1)
}
+// InitSettings initializes config provider and load common setttings for tests
+func InitSettings(extraConfigs ...string) {
+ setting.Init(&setting.Options{
+ AllowEmpty: true,
+ ExtraConfig: strings.Join(extraConfigs, "\n"),
+ })
+
+ if err := setting.PrepareAppDataPath(); err != nil {
+ log.Fatalf("Can not prepare APP_DATA_PATH: %v", err)
+ }
+ // register the dummy hash algorithm function used in the test fixtures
+ _ = hash.Register("dummy", hash.NewDummyHasher)
+
+ setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy")
+}
+
// TestOptions represents test options
type TestOptions struct {
GiteaRootPath string
@@ -50,6 +69,9 @@ type TestOptions struct {
// 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, testOpts *TestOptions) {
+ setting.SetCustomPathAndConf("", "", "")
+ InitSettings()
+
var err error
giteaRoot = testOpts.GiteaRootPath