summaryrefslogtreecommitdiffstats
path: root/models/unittest
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-04-27 20:23:37 +0800
committerGitHub <noreply@github.com>2024-04-27 12:23:37 +0000
commitd3cdef88ad4784c19afcf24fbf62fccb03f456ba (patch)
tree18e3a95c19b898202515227352e05b5ea2675c5b /models/unittest
parentdd301cae1c40c9ef2805bd13af6b09a81ff4f5d7 (diff)
downloadgitea-d3cdef88ad4784c19afcf24fbf62fccb03f456ba.tar.gz
gitea-d3cdef88ad4784c19afcf24fbf62fccb03f456ba.zip
Add some tests to clarify the "must-change-password" behavior (#30693)
Follow #30472: When a user is created by command line `./gitea admin user create`: Old behavior before #30472: the first user (admin or non-admin) doesn't need to change password. Revert to the old behavior before #30472
Diffstat (limited to 'models/unittest')
-rw-r--r--models/unittest/testdb.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go
index 51de18fa9b..53c9dbdd77 100644
--- a/models/unittest/testdb.go
+++ b/models/unittest/testdb.go
@@ -6,7 +6,6 @@ package unittest
import (
"context"
"fmt"
- "log"
"os"
"path/filepath"
"strings"
@@ -18,6 +17,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting/config"
"code.gitea.io/gitea/modules/storage"
@@ -46,6 +46,14 @@ func fatalTestError(fmtStr string, args ...any) {
// InitSettings initializes config provider and load common settings for tests
func InitSettings() {
+ setting.IsInTesting = true
+ log.OsExiter = func(code int) {
+ if code != 0 {
+ // non-zero exit code (log.Fatal) shouldn't occur during testing, if it happens, show a full stacktrace for more details
+ panic(fmt.Errorf("non-zero exit code during testing: %d", code))
+ }
+ os.Exit(0)
+ }
if setting.CustomConf == "" {
setting.CustomConf = filepath.Join(setting.CustomPath, "conf/app-unittest-tmp.ini")
_ = os.Remove(setting.CustomConf)
@@ -54,7 +62,7 @@ func InitSettings() {
setting.LoadCommonSettings()
if err := setting.PrepareAppDataPath(); err != nil {
- log.Fatalf("Can not prepare APP_DATA_PATH: %v", err)
+ log.Fatal("Can not prepare APP_DATA_PATH: %v", err)
}
// register the dummy hash algorithm function used in the test fixtures
_ = hash.Register("dummy", hash.NewDummyHasher)