Skip to content

Commit 95479fc

Browse files
Morgan PEYREpeyremorgan
authored andcommitted
test: stabilize cmd tests by centralizing InstallLock reset
After 07ada36, PrepareConsoleLoggerLevel can fail in tests when InstallLock is true. This commit fixes cmd test setup by forcing InstallLock=false in shared test execution paths. Changes: - cmd/main_test.go: set InstallLock=false in runTestApp and remove redundant per-subtest InstallLock mock in TestCliCmd. - cmd/config_test.go: set InstallLock=false in TestConfigEdit and add required imports. Co-Authored-By: GitHub Copilot <copilot@github.com> (GPT-5.3-Codex)
1 parent df8aa2f commit 95479fc

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

cmd/config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import (
77
"os"
88
"testing"
99

10+
"code.gitea.io/gitea/modules/setting"
11+
"code.gitea.io/gitea/modules/test"
12+
1013
"github.com/stretchr/testify/require"
1114
)
1215

1316
func TestConfigEdit(t *testing.T) {
17+
defer test.MockVariableValue(&setting.InstallLock, false)()
1418
tmpDir := t.TempDir()
1519
configOld := tmpDir + "/app-old.ini"
1620
configTemplate := tmpDir + "/app-template.ini"

cmd/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func runTestApp(app *cli.Command, args ...string) (runResult, error) {
5050
app.Writer = outBuf
5151
app.ErrWriter = errBuf
5252
exitCode := -1
53+
defer test.MockVariableValue(&setting.InstallLock, false)()
5354
defer test.MockVariableValue(&cli.ErrWriter, app.ErrWriter)()
5455
defer test.MockVariableValue(&cli.OsExiter, func(code int) {
5556
if exitCode == -1 {
@@ -157,7 +158,6 @@ func TestCliCmd(t *testing.T) {
157158

158159
for _, c := range cases {
159160
t.Run(c.cmd, func(t *testing.T) {
160-
defer test.MockVariableValue(&setting.InstallLock, false)()
161161
app := newTestApp(cli.Command{
162162
Action: func(ctx context.Context, cmd *cli.Command) error {
163163
_, _ = fmt.Fprint(cmd.Root().Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf))

0 commit comments

Comments
 (0)