diff --git a/cmd/main_test.go b/cmd/main_test.go index 0e32dce5648..a916c61f853 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -20,9 +20,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: "..", - }) + unittest.MainTest(m) } func makePathOutput(workPath, customPath, customConf string) string { diff --git a/models/activities/main_test.go b/models/activities/main_test.go index 6be54db658b..43afb84ef15 100644 --- a/models/activities/main_test.go +++ b/models/activities/main_test.go @@ -4,7 +4,6 @@ package activities_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,7 +13,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/asymkey/main_test.go b/models/asymkey/main_test.go index 701722be12e..be71f848d9d 100644 --- a/models/asymkey/main_test.go +++ b/models/asymkey/main_test.go @@ -4,7 +4,6 @@ package asymkey import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -12,7 +11,6 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), FixtureFiles: []string{ "gpg_key.yml", "public_key.yml", diff --git a/models/auth/main_test.go b/models/auth/main_test.go index f8cbf3bd546..d772ea6b1c8 100644 --- a/models/auth/main_test.go +++ b/models/auth/main_test.go @@ -4,7 +4,6 @@ package auth_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -17,7 +16,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/avatars/main_test.go b/models/avatars/main_test.go index 65076327177..c721a7dc2ac 100644 --- a/models/avatars/main_test.go +++ b/models/avatars/main_test.go @@ -4,7 +4,6 @@ package avatars_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -15,7 +14,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/db/main_test.go b/models/db/main_test.go index ce485029185..7d80b400fe5 100644 --- a/models/db/main_test.go +++ b/models/db/main_test.go @@ -4,7 +4,6 @@ package db_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,7 +13,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/db/paginator/main_test.go b/models/db/paginator/main_test.go index b0557bc5a4a..47993aed6be 100644 --- a/models/db/paginator/main_test.go +++ b/models/db/paginator/main_test.go @@ -4,14 +4,11 @@ package paginator import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/dbfs/main_test.go b/models/dbfs/main_test.go index 62db3592bed..537ba0935d6 100644 --- a/models/dbfs/main_test.go +++ b/models/dbfs/main_test.go @@ -4,14 +4,11 @@ package dbfs import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/git/main_test.go b/models/git/main_test.go index a8658d70c4c..aab1fa9a26f 100644 --- a/models/git/main_test.go +++ b/models/git/main_test.go @@ -4,7 +4,6 @@ package git_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -15,7 +14,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/issues/main_test.go b/models/issues/main_test.go index 190df027f4f..ba83ca55524 100644 --- a/models/issues/main_test.go +++ b/models/issues/main_test.go @@ -4,7 +4,6 @@ package issues_test import ( - "path/filepath" "testing" issues_model "code.gitea.io/gitea/models/issues" @@ -30,7 +29,5 @@ func TestFixturesAreConsistent(t *testing.T) { } func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/main_test.go b/models/main_test.go index c09b661d2c2..600dcc889b7 100644 --- a/models/main_test.go +++ b/models/main_test.go @@ -29,7 +29,5 @@ func TestFixturesAreConsistent(t *testing.T) { } func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: "..", - }) + unittest.MainTest(m) } diff --git a/models/organization/main_test.go b/models/organization/main_test.go index bc5bde2565c..c35898a465d 100644 --- a/models/organization/main_test.go +++ b/models/organization/main_test.go @@ -4,7 +4,6 @@ package organization_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -18,7 +17,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/packages/package_test.go b/models/packages/package_test.go index 525a9f08d62..7f03151e774 100644 --- a/models/packages/package_test.go +++ b/models/packages/package_test.go @@ -4,7 +4,6 @@ package packages_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/db" @@ -20,9 +19,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestHasOwnerPackages(t *testing.T) { diff --git a/models/perm/access/main_test.go b/models/perm/access/main_test.go index 8102cae4964..0a350dc41ea 100644 --- a/models/perm/access/main_test.go +++ b/models/perm/access/main_test.go @@ -4,7 +4,6 @@ package access_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -17,7 +16,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/project/main_test.go b/models/project/main_test.go index 816cbeb94a0..f4b2d6fedac 100644 --- a/models/project/main_test.go +++ b/models/project/main_test.go @@ -4,7 +4,6 @@ package project import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,7 +13,6 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), FixtureFiles: []string{ "project.yml", "project_board.yml", diff --git a/models/repo/main_test.go b/models/repo/main_test.go index ff97c7ac9ef..b49855f2c86 100644 --- a/models/repo/main_test.go +++ b/models/repo/main_test.go @@ -4,7 +4,6 @@ package repo_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -18,7 +17,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/system/main_test.go b/models/system/main_test.go index e074abc1551..6bc27a7cff8 100644 --- a/models/system/main_test.go +++ b/models/system/main_test.go @@ -4,7 +4,6 @@ package system_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -16,7 +15,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go index 1ff0fdc25bd..6db99cd393e 100644 --- a/models/unittest/testdb.go +++ b/models/unittest/testdb.go @@ -62,35 +62,46 @@ func InitSettings(extraConfigs ...string) { // TestOptions represents test options type TestOptions struct { - GiteaRootPath string - FixtureFiles []string - SetUp func() error // SetUp will be executed before all tests in this package - TearDown func() error // TearDown will be executed after all tests in this package + FixtureFiles []string + SetUp func() error // SetUp will be executed before all tests in this package + TearDown func() error // TearDown will be executed after all tests in this package } // 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.CustomPath = filepath.Join(testOpts.GiteaRootPath, "custom") - InitSettings() - - var err error +func MainTest(m *testing.M, testOpts ...*TestOptions) { + searchDir, _ := os.Getwd() + for searchDir != "" { + if _, err := os.Stat(filepath.Join(searchDir, "go.mod")); err == nil { + break // The "go.mod" should be the one for Gitea repository + } + if dir := filepath.Dir(searchDir); dir == searchDir { + searchDir = "" // reaches the root of filesystem + } else { + searchDir = dir + } + } + if searchDir == "" { + panic("The tests should run in a Gitea repository, there should be a 'go.mod' in the root") + } - giteaRoot = testOpts.GiteaRootPath - fixturesDir = filepath.Join(testOpts.GiteaRootPath, "models", "fixtures") + giteaRoot = searchDir + setting.CustomPath = filepath.Join(giteaRoot, "custom") + InitSettings() + fixturesDir = filepath.Join(giteaRoot, "models", "fixtures") var opts FixturesOptions - if len(testOpts.FixtureFiles) == 0 { + if len(testOpts) == 0 || len(testOpts[0].FixtureFiles) == 0 { opts.Dir = fixturesDir } else { - for _, f := range testOpts.FixtureFiles { + for _, f := range testOpts[0].FixtureFiles { if len(f) != 0 { opts.Files = append(opts.Files, filepath.Join(fixturesDir, f)) } } } - if err = CreateTestEngine(opts); err != nil { + if err := CreateTestEngine(opts); err != nil { fatalTestError("Error creating test engine: %v\n", err) } @@ -112,8 +123,8 @@ func MainTest(m *testing.M, testOpts *TestOptions) { fatalTestError("TempDir: %v\n", err) } setting.AppDataPath = appDataPath - setting.AppWorkPath = testOpts.GiteaRootPath - setting.StaticRootPath = testOpts.GiteaRootPath + setting.AppWorkPath = giteaRoot + setting.StaticRootPath = giteaRoot setting.GravatarSource = "https://secure.gravatar.com/avatar/" setting.Attachment.Storage.Path = filepath.Join(setting.AppDataPath, "attachments") @@ -144,7 +155,7 @@ func MainTest(m *testing.M, testOpts *TestOptions) { if err = util.RemoveAll(repoRootPath); err != nil { fatalTestError("util.RemoveAll: %v\n", err) } - if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil { + if err = CopyDir(filepath.Join(giteaRoot, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil { fatalTestError("util.CopyDir: %v\n", err) } @@ -171,16 +182,16 @@ func MainTest(m *testing.M, testOpts *TestOptions) { } } - if testOpts.SetUp != nil { - if err := testOpts.SetUp(); err != nil { + if len(testOpts) > 0 && testOpts[0].SetUp != nil { + if err := testOpts[0].SetUp(); err != nil { fatalTestError("set up failed: %v\n", err) } } exitStatus := m.Run() - if testOpts.TearDown != nil { - if err := testOpts.TearDown(); err != nil { + if len(testOpts) > 0 && testOpts[0].TearDown != nil { + if err := testOpts[0].TearDown(); err != nil { fatalTestError("tear down failed: %v\n", err) } } diff --git a/models/user/main_test.go b/models/user/main_test.go index 8833cc73862..a626d323a71 100644 --- a/models/user/main_test.go +++ b/models/user/main_test.go @@ -4,7 +4,6 @@ package user_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -16,7 +15,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/models/webhook/main_test.go b/models/webhook/main_test.go index 8df569a3ccf..f19465d5053 100644 --- a/models/webhook/main_test.go +++ b/models/webhook/main_test.go @@ -4,7 +4,6 @@ package webhook import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -12,7 +11,6 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), FixtureFiles: []string{ "webhook.yml", "hook_task.yml", diff --git a/modules/activitypub/main_test.go b/modules/activitypub/main_test.go index dcd57bb59e5..4591f1fa555 100644 --- a/modules/activitypub/main_test.go +++ b/modules/activitypub/main_test.go @@ -4,7 +4,6 @@ package activitypub import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -15,7 +14,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go index 2a650646bd9..5b2a97d3d5f 100644 --- a/modules/indexer/code/indexer_test.go +++ b/modules/indexer/code/indexer_test.go @@ -6,7 +6,6 @@ package code import ( "context" "os" - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -23,9 +22,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } func testIndexer(name string, t *testing.T, indexer internal.Indexer) { diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 7241f6313c8..0ec23164c28 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -5,7 +5,6 @@ package issues import ( "context" - "path/filepath" "testing" "code.gitea.io/gitea/models/db" @@ -22,9 +21,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } func TestDBSearchIssues(t *testing.T) { diff --git a/modules/indexer/stats/indexer_test.go b/modules/indexer/stats/indexer_test.go index c0315154340..6f935a20de3 100644 --- a/modules/indexer/stats/indexer_test.go +++ b/modules/indexer/stats/indexer_test.go @@ -5,7 +5,6 @@ package stats import ( "context" - "path/filepath" "testing" "time" @@ -23,9 +22,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } func TestRepoStatsIndex(t *testing.T) { diff --git a/modules/repository/main_test.go b/modules/repository/main_test.go index abaae698663..f81dfcdafbc 100644 --- a/modules/repository/main_test.go +++ b/modules/repository/main_test.go @@ -4,7 +4,6 @@ package repository import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -13,7 +12,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/modules/system/appstate_test.go b/modules/system/appstate_test.go index 65a6e500033..232362cf0c8 100644 --- a/modules/system/appstate_test.go +++ b/modules/system/appstate_test.go @@ -4,7 +4,6 @@ package system import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,8 +13,7 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - FixtureFiles: []string{""}, // load nothing + FixtureFiles: []string{""}, // load nothing }) } diff --git a/routers/api/v1/repo/main_test.go b/routers/api/v1/repo/main_test.go index bc048505f47..451f34d72ff 100644 --- a/routers/api/v1/repo/main_test.go +++ b/routers/api/v1/repo/main_test.go @@ -4,7 +4,6 @@ package repo import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,7 +13,6 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", "..", ".."), SetUp: func() error { setting.LoadQueueSettings() return webhook_service.Init() diff --git a/routers/common/errpage_test.go b/routers/common/errpage_test.go index ea9a9e745c1..58a633b2a45 100644 --- a/routers/common/errpage_test.go +++ b/routers/common/errpage_test.go @@ -9,7 +9,6 @@ import ( "net/http" "net/http/httptest" "net/url" - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -35,7 +34,5 @@ func TestRenderPanicErrorPage(t *testing.T) { } func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/install/routes_test.go b/routers/install/routes_test.go index fcbd0529774..2aa7f5d7b73 100644 --- a/routers/install/routes_test.go +++ b/routers/install/routes_test.go @@ -5,7 +5,6 @@ package install import ( "net/http/httptest" - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -35,7 +34,5 @@ func TestRoutes(t *testing.T) { } func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/private/main_test.go b/routers/private/main_test.go index 700af6ec8d4..a6bec72b41d 100644 --- a/routers/private/main_test.go +++ b/routers/private/main_test.go @@ -4,14 +4,11 @@ package private import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/admin/main_test.go b/routers/web/admin/main_test.go index ea79830fa13..e1294ddbb40 100644 --- a/routers/web/admin/main_test.go +++ b/routers/web/admin/main_test.go @@ -4,14 +4,11 @@ package admin import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/auth/main_test.go b/routers/web/auth/main_test.go index 8295515ba95..b438e5d5188 100644 --- a/routers/web/auth/main_test.go +++ b/routers/web/auth/main_test.go @@ -4,14 +4,11 @@ package auth import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/org/main_test.go b/routers/web/org/main_test.go index 41323a3601e..92237d6e884 100644 --- a/routers/web/org/main_test.go +++ b/routers/web/org/main_test.go @@ -4,14 +4,11 @@ package org_test import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/repo/main_test.go b/routers/web/repo/main_test.go index e3a09a95bd3..6e469cf2ed7 100644 --- a/routers/web/repo/main_test.go +++ b/routers/web/repo/main_test.go @@ -4,14 +4,11 @@ package repo import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/repo/setting/main_test.go b/routers/web/repo/setting/main_test.go index 5a6fa562177..c414b853e51 100644 --- a/routers/web/repo/setting/main_test.go +++ b/routers/web/repo/setting/main_test.go @@ -4,14 +4,11 @@ package setting import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/user/main_test.go b/routers/web/user/main_test.go index 925482a1d2b..8b6ae69296b 100644 --- a/routers/web/user/main_test.go +++ b/routers/web/user/main_test.go @@ -4,14 +4,11 @@ package user import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/routers/web/user/setting/main_test.go b/routers/web/user/setting/main_test.go index c3938b32011..e398208d0da 100644 --- a/routers/web/user/setting/main_test.go +++ b/routers/web/user/setting/main_test.go @@ -4,14 +4,11 @@ package setting import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", "..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/asymkey/main_test.go b/services/asymkey/main_test.go index e7a03861b9c..3505b26f699 100644 --- a/services/asymkey/main_test.go +++ b/services/asymkey/main_test.go @@ -4,7 +4,6 @@ package asymkey import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,7 +13,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/attachment/attachment_test.go b/services/attachment/attachment_test.go index 35fcef7445c..77ef1cd37ce 100644 --- a/services/attachment/attachment_test.go +++ b/services/attachment/attachment_test.go @@ -19,9 +19,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestUploadAttachment(t *testing.T) { diff --git a/services/convert/main_test.go b/services/convert/main_test.go index c2298dcb74a..363cc4a97f5 100644 --- a/services/convert/main_test.go +++ b/services/convert/main_test.go @@ -4,7 +4,6 @@ package convert import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -13,7 +12,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/feed/action_test.go b/services/feed/action_test.go index fd84bb675b1..e1b071d8f60 100644 --- a/services/feed/action_test.go +++ b/services/feed/action_test.go @@ -4,7 +4,6 @@ package feed import ( - "path/filepath" "strings" "testing" @@ -20,9 +19,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestRenameRepoAction(t *testing.T) { diff --git a/services/gitdiff/main_test.go b/services/gitdiff/main_test.go index 7f4243576cc..cd9dcd8cd6f 100644 --- a/services/gitdiff/main_test.go +++ b/services/gitdiff/main_test.go @@ -4,7 +4,6 @@ package gitdiff import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -15,7 +14,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/issue/main_test.go b/services/issue/main_test.go index 6bce694ccaf..5dac54183ba 100644 --- a/services/issue/main_test.go +++ b/services/issue/main_test.go @@ -4,7 +4,6 @@ package issue import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -13,7 +12,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/mailer/main_test.go b/services/mailer/main_test.go index e906f4cb6e1..f803c736ca1 100644 --- a/services/mailer/main_test.go +++ b/services/mailer/main_test.go @@ -4,7 +4,6 @@ package mailer import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -13,7 +12,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/markup/main_test.go b/services/markup/main_test.go index ce892435a1a..89fe3e7e346 100644 --- a/services/markup/main_test.go +++ b/services/markup/main_test.go @@ -4,7 +4,6 @@ package markup import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -12,7 +11,6 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - FixtureFiles: []string{"user.yml"}, + FixtureFiles: []string{"user.yml"}, }) } diff --git a/services/migrations/main_test.go b/services/migrations/main_test.go index 42c433fb003..d0ec6a3f8d7 100644 --- a/services/migrations/main_test.go +++ b/services/migrations/main_test.go @@ -5,7 +5,6 @@ package migrations import ( - "path/filepath" "testing" "time" @@ -16,9 +15,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func timePtr(t time.Time) *time.Time { diff --git a/services/org/org_test.go b/services/org/org_test.go index cc22595c6f1..339646795da 100644 --- a/services/org/org_test.go +++ b/services/org/org_test.go @@ -4,7 +4,6 @@ package org import ( - "path/filepath" "testing" "code.gitea.io/gitea/models" @@ -16,9 +15,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestDeleteOrganization(t *testing.T) { diff --git a/services/pull/main_test.go b/services/pull/main_test.go index f5297354d65..efbb63a36ec 100644 --- a/services/pull/main_test.go +++ b/services/pull/main_test.go @@ -5,7 +5,6 @@ package pull import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -14,7 +13,5 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/release/release_test.go b/services/release/release_test.go index 9c652f28d2e..3f0c67b0e01 100644 --- a/services/release/release_test.go +++ b/services/release/release_test.go @@ -4,7 +4,6 @@ package release import ( - "path/filepath" "strings" "testing" "time" @@ -22,9 +21,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestRelease_Create(t *testing.T) { diff --git a/services/repository/archiver/archiver_test.go b/services/repository/archiver/archiver_test.go index a1bc355d4e9..ff8bb8ca7a9 100644 --- a/services/repository/archiver/archiver_test.go +++ b/services/repository/archiver/archiver_test.go @@ -5,7 +5,6 @@ package archiver import ( "errors" - "path/filepath" "testing" "time" @@ -18,9 +17,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } func TestArchive_Basic(t *testing.T) { diff --git a/services/repository/files/content_test.go b/services/repository/files/content_test.go index d591c468399..3ad3e3ab98b 100644 --- a/services/repository/files/content_test.go +++ b/services/repository/files/content_test.go @@ -4,7 +4,6 @@ package files import ( - "path/filepath" "testing" repo_model "code.gitea.io/gitea/models/repo" @@ -19,9 +18,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) + unittest.MainTest(m) } func getExpectedReadmeContentsResponse() *api.ContentsResponse { diff --git a/services/repository/main_test.go b/services/repository/main_test.go index 007790f2a96..7ad1540aee4 100644 --- a/services/repository/main_test.go +++ b/services/repository/main_test.go @@ -4,14 +4,11 @@ package repository import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } diff --git a/services/user/user_test.go b/services/user/user_test.go index b8f7b9b1a25..550dafd9c56 100644 --- a/services/user/user_test.go +++ b/services/user/user_test.go @@ -5,7 +5,6 @@ package user import ( "fmt" - "path/filepath" "strings" "testing" @@ -22,9 +21,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestDeleteUser(t *testing.T) { diff --git a/services/webhook/main_test.go b/services/webhook/main_test.go index cd34c02b5c5..756b9db2308 100644 --- a/services/webhook/main_test.go +++ b/services/webhook/main_test.go @@ -4,7 +4,6 @@ package webhook import ( - "path/filepath" "testing" "code.gitea.io/gitea/models/unittest" @@ -19,7 +18,6 @@ func TestMain(m *testing.M) { // for tests, allow only loopback IPs setting.Webhook.AllowedHostList = hostmatcher.MatchBuiltinLoopback unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), SetUp: func() error { setting.LoadQueueSettings() return Init() diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go index 81a688b046a..e8da176a08d 100644 --- a/services/wiki/wiki_test.go +++ b/services/wiki/wiki_test.go @@ -5,7 +5,6 @@ package wiki import ( "math/rand" - "path/filepath" "strings" "testing" @@ -20,9 +19,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", ".."), - }) + unittest.MainTest(m) } func TestWebPathSegments(t *testing.T) {