Skip to content

Commit 7d14c6f

Browse files
committed
Filter out gitea-specific variables in tests
There is no particular reason to set gitea variables globally. Nonetheless, some misguided packagers set GITEA_CUSTOM in /etc/profile breaking tests. Fixes: #36042
1 parent c287a8c commit 7d14c6f

File tree

16 files changed

+105
-0
lines changed

16 files changed

+105
-0
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ jobs:
138138
- name: unit-tests
139139
run: make unit-test-coverage test-check
140140
env:
141+
GITEA_ROOT: foo
142+
GITEA_CONF: bar
143+
GITEA_CUSTOM: baz
141144
TAGS: bindata
142145
RACE_ENABLED: true
143146
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}

models/unittest/fixtures_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.gitea.io/gitea/models/unittest"
1111
user_model "code.gitea.io/gitea/models/user"
1212
"code.gitea.io/gitea/modules/test"
13+
"code.gitea.io/gitea/tests/env"
1314

1415
"github.com/stretchr/testify/require"
1516
"xorm.io/xorm"
@@ -112,3 +113,8 @@ func BenchmarkFixturesLoader(b *testing.B) {
112113
}
113114
})
114115
}
116+
117+
func TestMain(m *testing.M) {
118+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
119+
m.Run()
120+
}

models/unittest/testdb.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"code.gitea.io/gitea/modules/tempdir"
2424
"code.gitea.io/gitea/modules/test"
2525
"code.gitea.io/gitea/modules/util"
26+
"code.gitea.io/gitea/tests/env"
2627

2728
"github.com/stretchr/testify/assert"
2829
"xorm.io/xorm"
@@ -73,6 +74,7 @@ type TestOptions struct {
7374
// MainTest a reusable TestMain(..) function for unit tests that need to use a
7475
// test database. Creates the test database, and sets necessary settings.
7576
func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
77+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
7678
testOpts := util.OptionalArg(testOptsArg, &TestOptions{})
7779
giteaRoot = test.SetupGiteaRoot()
7880
setting.CustomPath = filepath.Join(giteaRoot, "custom")

modules/git/attribute/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/git"
1212
"code.gitea.io/gitea/modules/setting"
1313
"code.gitea.io/gitea/modules/util"
14+
"code.gitea.io/gitea/tests/env"
1415
)
1516

1617
func testRun(m *testing.M) error {
@@ -33,6 +34,7 @@ func testRun(m *testing.M) error {
3334
}
3435

3536
func TestMain(m *testing.M) {
37+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
3638
if err := testRun(m); err != nil {
3739
_, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
3840
os.Exit(1)

modules/git/git_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/modules/setting"
1212
"code.gitea.io/gitea/modules/tempdir"
13+
"code.gitea.io/gitea/tests/env"
1314

1415
"github.com/hashicorp/go-version"
1516
"github.com/stretchr/testify/assert"
@@ -36,6 +37,7 @@ func testRun(m *testing.M) error {
3637
}
3738

3839
func TestMain(m *testing.M) {
40+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
3941
if err := testRun(m); err != nil {
4042
_, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
4143
os.Exit(1)

modules/git/gitcmd/command_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010

1111
"code.gitea.io/gitea/modules/setting"
1212
"code.gitea.io/gitea/modules/tempdir"
13+
"code.gitea.io/gitea/tests/env"
1314

1415
"github.com/stretchr/testify/assert"
1516
)
1617

1718
func TestMain(m *testing.M) {
19+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
1820
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
1921
if err != nil {
2022
_, _ = fmt.Fprintf(os.Stderr, "unable to create temp dir: %v", err)

modules/git/languagestats/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/git"
1212
"code.gitea.io/gitea/modules/setting"
1313
"code.gitea.io/gitea/modules/util"
14+
"code.gitea.io/gitea/tests/env"
1415
)
1516

1617
func testRun(m *testing.M) error {
@@ -33,6 +34,7 @@ func testRun(m *testing.M) error {
3334
}
3435

3536
func TestMain(m *testing.M) {
37+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
3638
if err := testRun(m); err != nil {
3739
_, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
3840
os.Exit(1)

modules/gitrepo/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
"code.gitea.io/gitea/modules/setting"
1313
"code.gitea.io/gitea/modules/tempdir"
1414
"code.gitea.io/gitea/modules/test"
15+
"code.gitea.io/gitea/tests/env"
1516
)
1617

1718
func TestMain(m *testing.M) {
19+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
1820
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
1921
if err != nil {
2022
log.Fatal("Unable to create temp dir: %v", err)

modules/markup/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99

1010
"code.gitea.io/gitea/modules/markup"
1111
"code.gitea.io/gitea/modules/setting"
12+
"code.gitea.io/gitea/tests/env"
1213
)
1314

1415
func TestMain(m *testing.M) {
16+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
1517
setting.IsInTesting = true
1618
markup.RenderBehaviorForTesting.DisableAdditionalAttributes = true
1719
os.Exit(m.Run())

modules/markup/markdown/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99

1010
"code.gitea.io/gitea/modules/markup"
1111
"code.gitea.io/gitea/modules/setting"
12+
"code.gitea.io/gitea/tests/env"
1213
)
1314

1415
func TestMain(m *testing.M) {
16+
env.Filter([]string{"GITEA_TEST_"}, []string{"GITEA_"})
1517
setting.IsInTesting = true
1618
markup.RenderBehaviorForTesting.DisableAdditionalAttributes = true
1719
os.Exit(m.Run())

0 commit comments

Comments
 (0)