From 673cf6af763fe7fd4301382f7b059b0799fca396 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 28 Sep 2023 09:38:53 +0800 Subject: [PATCH] make writing main test easier (#27270) This PR removed `unittest.MainTest` the second parameter `TestOptions.GiteaRoot`. Now it detects the root directory by current working directory. --------- Co-authored-by: wxiaoguang --- cmd/main_test.go | 4 +- models/activities/main_test.go | 5 +- models/asymkey/main_test.go | 2 - models/auth/main_test.go | 5 +- models/avatars/main_test.go | 5 +- models/db/main_test.go | 5 +- models/db/paginator/main_test.go | 5 +- models/dbfs/main_test.go | 5 +- models/git/main_test.go | 5 +- models/issues/main_test.go | 5 +- models/main_test.go | 4 +- models/organization/main_test.go | 5 +- models/packages/package_test.go | 5 +- models/perm/access/main_test.go | 5 +- models/project/main_test.go | 2 - models/repo/main_test.go | 5 +- models/system/main_test.go | 5 +- models/unittest/testdb.go | 53 +++++++++++-------- models/user/main_test.go | 5 +- models/webhook/main_test.go | 2 - modules/activitypub/main_test.go | 5 +- modules/indexer/code/indexer_test.go | 5 +- modules/indexer/issues/indexer_test.go | 5 +- modules/indexer/stats/indexer_test.go | 5 +- modules/repository/main_test.go | 5 +- modules/system/appstate_test.go | 4 +- routers/api/v1/repo/main_test.go | 2 - routers/common/errpage_test.go | 5 +- routers/install/routes_test.go | 5 +- routers/private/main_test.go | 5 +- routers/web/admin/main_test.go | 5 +- routers/web/auth/main_test.go | 5 +- routers/web/org/main_test.go | 5 +- routers/web/repo/main_test.go | 5 +- routers/web/repo/setting/main_test.go | 5 +- routers/web/user/main_test.go | 5 +- routers/web/user/setting/main_test.go | 5 +- services/asymkey/main_test.go | 5 +- services/attachment/attachment_test.go | 4 +- services/convert/main_test.go | 5 +- services/feed/action_test.go | 5 +- services/gitdiff/main_test.go | 5 +- services/issue/main_test.go | 5 +- services/mailer/main_test.go | 5 +- services/markup/main_test.go | 4 +- services/migrations/main_test.go | 5 +- services/org/org_test.go | 5 +- services/pull/main_test.go | 5 +- services/release/release_test.go | 5 +- services/repository/archiver/archiver_test.go | 5 +- services/repository/files/content_test.go | 5 +- services/repository/main_test.go | 5 +- services/user/user_test.go | 5 +- services/webhook/main_test.go | 2 - services/wiki/wiki_test.go | 5 +- 55 files changed, 81 insertions(+), 222 deletions(-) diff --git a/cmd/main_test.go b/cmd/main_test.go index 0e32dce564..a916c61f85 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 6be54db658..43afb84ef1 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 701722be12..be71f848d9 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 f8cbf3bd54..d772ea6b1c 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 6507632717..c721a7dc2a 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 ce48502918..7d80b400fe 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 b0557bc5a4..47993aed6b 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 62db3592be..537ba0935d 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 a8658d70c4..aab1fa9a26 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 190df027f4..ba83ca5552 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 c09b661d2c..600dcc889b 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 bc5bde2565..c35898a465 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 525a9f08d6..7f03151e77 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 8102cae496..0a350dc41e 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 816cbeb94a..f4b2d6feda 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 ff97c7ac9e..b49855f2c8 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 e074abc155..6bc27a7cff 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 1ff0fdc25b..6db99cd393 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") +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 = searchDir + setting.CustomPath = filepath.Join(giteaRoot, "custom") InitSettings() - var err error - - giteaRoot = testOpts.GiteaRootPath - fixturesDir = filepath.Join(testOpts.GiteaRootPath, "models", "fixtures") - + 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 8833cc7386..a626d323a7 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 8df569a3cc..f19465d505 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 dcd57bb59e..4591f1fa55 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 2a650646bd..5b2a97d3d5 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 7241f6313c..0ec23164c2 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 c031515434..6f935a20de 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 abaae69866..f81dfcdafb 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 65a6e50003..232362cf0c 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 bc048505f4..451f34d72f 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 ea9a9e745c..58a633b2a4 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 fcbd052977..2aa7f5d7b7 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 700af6ec8d..a6bec72b41 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 ea79830fa1..e1294ddbb4 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 8295515ba9..b438e5d518 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 41323a3601..92237d6e88 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 e3a09a95bd..6e469cf2ed 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 5a6fa56217..c414b853e5 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 925482a1d2..8b6ae69296 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 c3938b3201..e398208d0d 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 e7a03861b9..3505b26f69 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 35fcef7445..77ef1cd37c 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 c2298dcb74..363cc4a97f 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 fd84bb675b..e1b071d8f6 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 7f4243576c..cd9dcd8cd6 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 6bce694cca..5dac54183b 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 e906f4cb6e..f803c736ca 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 ce892435a1..89fe3e7e34 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 42c433fb00..d0ec6a3f8d 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 cc22595c6f..339646795d 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 f5297354d6..efbb63a36e 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 9c652f28d2..3f0c67b0e0 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 a1bc355d4e..ff8bb8ca7a 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 d591c46839..3ad3e3ab98 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 007790f2a9..7ad1540aee 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 b8f7b9b1a2..550dafd9c5 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 cd34c02b5c..756b9db230 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 81a688b046..e8da176a08 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) {