From b8911fb45673fdc3fce587892c4d9215e7c15019 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 14 Apr 2022 21:58:21 +0800 Subject: [PATCH] Use a struct as test options (#19393) * Use a struct as test options * Fix name * Fix test --- models/admin/main_test.go | 7 ++-- models/asymkey/main_test.go | 19 ++++++---- models/auth/main_test.go | 17 +++++---- models/db/paginator/main_test.go | 4 +- models/issues/main_test.go | 15 +++++--- models/main_test.go | 4 +- models/organization/main_test.go | 21 ++++++----- models/project/main_test.go | 15 +++++--- models/repo/main_test.go | 29 ++++++++------- models/unittest/testdb.go | 37 +++++++++++++++---- models/user/main_test.go | 21 ++++++----- models/webhook/main_test.go | 8 +++- modules/appstate/appstate_test.go | 5 ++- modules/convert/main_test.go | 4 +- modules/indexer/code/indexer_test.go | 4 +- modules/indexer/issues/indexer_test.go | 4 +- modules/indexer/stats/indexer_test.go | 4 +- modules/notification/action/action_test.go | 4 +- modules/repository/main_test.go | 4 +- routers/api/v1/repo/main_test.go | 4 +- routers/web/admin/main_test.go | 4 +- routers/web/auth/main_test.go | 4 +- routers/web/repo/main_test.go | 4 +- routers/web/user/main_test.go | 4 +- routers/web/user/setting/main_test.go | 4 +- services/asymkey/main_test.go | 4 +- services/attachment/attachment_test.go | 4 +- services/gitdiff/main_test.go | 4 +- services/issue/main_test.go | 4 +- services/mailer/main_test.go | 4 +- services/migrations/main_test.go | 4 +- services/org/org_test.go | 4 +- services/pull/main_test.go | 4 +- services/release/release_test.go | 4 +- services/repository/archiver/archiver_test.go | 4 +- services/repository/files/content_test.go | 4 +- services/repository/main_test.go | 4 +- services/user/user_test.go | 4 +- services/webhook/main_test.go | 4 +- services/wiki/wiki_test.go | 4 +- 40 files changed, 210 insertions(+), 100 deletions(-) diff --git a/models/admin/main_test.go b/models/admin/main_test.go index f6c9dce57ad7..693b70fbf758 100644 --- a/models/admin/main_test.go +++ b/models/admin/main_test.go @@ -12,7 +12,8 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "notice.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{"notice.yml"}, + }) } diff --git a/models/asymkey/main_test.go b/models/asymkey/main_test.go index 1c4f7752e2f1..9f53e335fec9 100644 --- a/models/asymkey/main_test.go +++ b/models/asymkey/main_test.go @@ -18,12 +18,15 @@ func init() { } func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "gpg_key.yml", - "public_key.yml", - "deploy_key.yml", - "gpg_key_import.yml", - "user.yml", - "email_address.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "gpg_key.yml", + "public_key.yml", + "deploy_key.yml", + "gpg_key_import.yml", + "user.yml", + "email_address.yml", + }, + }) } diff --git a/models/auth/main_test.go b/models/auth/main_test.go index 4255f488fe60..ccbdd4e81c7c 100644 --- a/models/auth/main_test.go +++ b/models/auth/main_test.go @@ -12,11 +12,14 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "login_source.yml", - "oauth2_application.yml", - "oauth2_authorization_code.yml", - "oauth2_grant.yml", - "webauthn_credential.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "login_source.yml", + "oauth2_application.yml", + "oauth2_authorization_code.yml", + "oauth2_grant.yml", + "webauthn_credential.yml", + }, + }) } diff --git a/models/db/paginator/main_test.go b/models/db/paginator/main_test.go index 601ed89710a3..1127987e53d9 100644 --- a/models/db/paginator/main_test.go +++ b/models/db/paginator/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } diff --git a/models/issues/main_test.go b/models/issues/main_test.go index bec6176abdb2..30f6ff02fb49 100644 --- a/models/issues/main_test.go +++ b/models/issues/main_test.go @@ -18,10 +18,13 @@ func init() { } func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "reaction.yml", - "user.yml", - "repository.yml", - "milestone.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "reaction.yml", + "user.yml", + "repository.yml", + "milestone.yml", + }, + }) } diff --git a/models/main_test.go b/models/main_test.go index 00da59cbe658..96231e4704d1 100644 --- a/models/main_test.go +++ b/models/main_test.go @@ -37,5 +37,7 @@ func TestFixturesAreConsistent(t *testing.T) { } func TestMain(m *testing.M) { - unittest.MainTest(m, "..") + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: "..", + }) } diff --git a/models/organization/main_test.go b/models/organization/main_test.go index a2cb91102167..711b86b9bd19 100644 --- a/models/organization/main_test.go +++ b/models/organization/main_test.go @@ -12,13 +12,16 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "user.yml", - "org_user.yml", - "team.yml", - "team_repo.yml", - "team_unit.yml", - "team_user.yml", - "repository.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "user.yml", + "org_user.yml", + "team.yml", + "team_repo.yml", + "team_unit.yml", + "team_user.yml", + "repository.yml", + }, + }) } diff --git a/models/project/main_test.go b/models/project/main_test.go index 5296a0f40e78..2e97b3a5ef3b 100644 --- a/models/project/main_test.go +++ b/models/project/main_test.go @@ -14,10 +14,13 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "project.yml", - "project_board.yml", - "project_issue.yml", - "repository.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "project.yml", + "project_board.yml", + "project_issue.yml", + "repository.yml", + }, + }) } diff --git a/models/repo/main_test.go b/models/repo/main_test.go index fdd6c3f4d308..e375e8a9f3dd 100644 --- a/models/repo/main_test.go +++ b/models/repo/main_test.go @@ -12,17 +12,20 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "attachment.yml", - "repo_archiver.yml", - "repository.yml", - "repo_unit.yml", - "repo_indexer_status.yml", - "repo_redirect.yml", - "watch.yml", - "star.yml", - "topic.yml", - "repo_topic.yml", - "user.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "attachment.yml", + "repo_archiver.yml", + "repository.yml", + "repo_unit.yml", + "repo_indexer_status.yml", + "repo_redirect.yml", + "watch.yml", + "star.yml", + "topic.yml", + "repo_topic.yml", + "user.yml", + }, + }) } diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go index 4f1bd63f29a7..117614a7a4f3 100644 --- a/models/unittest/testdb.go +++ b/models/unittest/testdb.go @@ -39,19 +39,27 @@ func fatalTestError(fmtStr string, args ...interface{}) { os.Exit(1) } +// 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 +} + // 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, pathToGiteaRoot string, fixtureFiles ...string) { +func MainTest(m *testing.M, testOpts *TestOptions) { var err error - giteaRoot = pathToGiteaRoot - fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures") + giteaRoot = testOpts.GiteaRootPath + fixturesDir = filepath.Join(testOpts.GiteaRootPath, "models", "fixtures") var opts FixturesOptions - if len(fixtureFiles) == 0 { + if len(testOpts.FixtureFiles) == 0 { opts.Dir = fixturesDir } else { - for _, f := range fixtureFiles { + for _, f := range testOpts.FixtureFiles { if len(f) != 0 { opts.Files = append(opts.Files, filepath.Join(fixturesDir, f)) } @@ -80,8 +88,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) { fatalTestError("TempDir: %v\n", err) } setting.AppDataPath = appDataPath - setting.AppWorkPath = pathToGiteaRoot - setting.StaticRootPath = pathToGiteaRoot + setting.AppWorkPath = testOpts.GiteaRootPath + setting.StaticRootPath = testOpts.GiteaRootPath setting.GravatarSourceURL, err = url.Parse("https://secure.gravatar.com/avatar/") if err != nil { fatalTestError("url.Parse: %v\n", err) @@ -105,7 +113,7 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) { if err = util.RemoveAll(repoRootPath); err != nil { fatalTestError("util.RemoveAll: %v\n", err) } - if err = CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil { + if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil { fatalTestError("util.CopyDir: %v\n", err) } @@ -129,7 +137,20 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) { } } + if testOpts.SetUp != nil { + if err := testOpts.SetUp(); err != nil { + fatalTestError("set up failed: %v\n", err) + } + } + exitStatus := m.Run() + + if testOpts.TearDown != nil { + if err := testOpts.TearDown(); err != nil { + fatalTestError("tear down failed: %v\n", err) + } + } + if err = util.RemoveAll(repoRootPath); err != nil { fatalTestError("util.RemoveAll: %v\n", err) } diff --git a/models/user/main_test.go b/models/user/main_test.go index 55e5f9341cd9..09af550a9594 100644 --- a/models/user/main_test.go +++ b/models/user/main_test.go @@ -12,13 +12,16 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), - "email_address.yml", - "user_redirect.yml", - "follow.yml", - "user_open_id.yml", - "two_factor.yml", - "oauth2_application.yml", - "user.yml", - ) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "email_address.yml", + "user_redirect.yml", + "follow.yml", + "user_open_id.yml", + "two_factor.yml", + "oauth2_application.yml", + "user.yml", + }, + }) } diff --git a/models/webhook/main_test.go b/models/webhook/main_test.go index 89c947b061fd..39ef2da6a25c 100644 --- a/models/webhook/main_test.go +++ b/models/webhook/main_test.go @@ -12,5 +12,11 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), "webhook.yml", "hook_task.yml") + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{ + "webhook.yml", + "hook_task.yml", + }, + }) } diff --git a/modules/appstate/appstate_test.go b/modules/appstate/appstate_test.go index 15fbc829bae4..e4a0d72850e7 100644 --- a/modules/appstate/appstate_test.go +++ b/modules/appstate/appstate_test.go @@ -14,7 +14,10 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", ".."), "") + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + FixtureFiles: []string{""}, // load nothing + }) } type testItem1 struct { diff --git a/modules/convert/main_test.go b/modules/convert/main_test.go index 307fd06197ce..84f16b9af38a 100644 --- a/modules/convert/main_test.go +++ b/modules/convert/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go index d56c33653f32..06923dfd25d3 100644 --- a/modules/indexer/code/indexer_test.go +++ b/modules/indexer/code/indexer_test.go @@ -18,7 +18,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } func testIndexer(name string, t *testing.T, indexer Indexer) { diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index d516615b56eb..6bafcbdf24d3 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -23,7 +23,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } func TestBleveSearchIssues(t *testing.T) { diff --git a/modules/indexer/stats/indexer_test.go b/modules/indexer/stats/indexer_test.go index b5c58ab25afa..c8bd8d1783d2 100644 --- a/modules/indexer/stats/indexer_test.go +++ b/modules/indexer/stats/indexer_test.go @@ -23,7 +23,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } func TestRepoStatsIndex(t *testing.T) { diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go index 3664b8210471..2898c8ec3de4 100644 --- a/modules/notification/action/action_test.go +++ b/modules/notification/action/action_test.go @@ -18,7 +18,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } func TestRenameRepoAction(t *testing.T) { diff --git a/modules/repository/main_test.go b/modules/repository/main_test.go index 262d3394818b..42134fa7adab 100644 --- a/modules/repository/main_test.go +++ b/modules/repository/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/routers/api/v1/repo/main_test.go b/routers/api/v1/repo/main_test.go index f9ed886999c9..19e524d014f7 100644 --- a/routers/api/v1/repo/main_test.go +++ b/routers/api/v1/repo/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", "..", ".."), + }) } diff --git a/routers/web/admin/main_test.go b/routers/web/admin/main_test.go index e41d8fea75c3..4e6ad4d743f6 100644 --- a/routers/web/admin/main_test.go +++ b/routers/web/admin/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } diff --git a/routers/web/auth/main_test.go b/routers/web/auth/main_test.go index 2b16f3c4059b..71f522fb0754 100644 --- a/routers/web/auth/main_test.go +++ b/routers/web/auth/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } diff --git a/routers/web/repo/main_test.go b/routers/web/repo/main_test.go index 81e3a8e28135..a1ca3c3bc716 100644 --- a/routers/web/repo/main_test.go +++ b/routers/web/repo/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } diff --git a/routers/web/user/main_test.go b/routers/web/user/main_test.go index 77b48d89fb86..517957a85cd9 100644 --- a/routers/web/user/main_test.go +++ b/routers/web/user/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } diff --git a/routers/web/user/setting/main_test.go b/routers/web/user/setting/main_test.go index b6ed7f5b1803..d4df464abd82 100644 --- a/routers/web/user/setting/main_test.go +++ b/routers/web/user/setting/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", "..", ".."), + }) } diff --git a/services/asymkey/main_test.go b/services/asymkey/main_test.go index a891a10cf6b4..cb3d05945658 100644 --- a/services/asymkey/main_test.go +++ b/services/asymkey/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/attachment/attachment_test.go b/services/attachment/attachment_test.go index 9ebd0d29ab44..ffce5943e5cf 100644 --- a/services/attachment/attachment_test.go +++ b/services/attachment/attachment_test.go @@ -17,7 +17,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } func TestUploadAttachment(t *testing.T) { diff --git a/services/gitdiff/main_test.go b/services/gitdiff/main_test.go index 8c76e7e1530f..d4d9364ebf49 100644 --- a/services/gitdiff/main_test.go +++ b/services/gitdiff/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/issue/main_test.go b/services/issue/main_test.go index cbcfd08a4979..689ae744f681 100644 --- a/services/issue/main_test.go +++ b/services/issue/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/mailer/main_test.go b/services/mailer/main_test.go index ae3b2c12b4ca..0bd154113f03 100644 --- a/services/mailer/main_test.go +++ b/services/mailer/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/migrations/main_test.go b/services/migrations/main_test.go index b040df83d14b..ad9bc9c731eb 100644 --- a/services/migrations/main_test.go +++ b/services/migrations/main_test.go @@ -17,7 +17,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } func timePtr(t time.Time) *time.Time { diff --git a/services/org/org_test.go b/services/org/org_test.go index b30bfddbb443..7f90d85807a7 100644 --- a/services/org/org_test.go +++ b/services/org/org_test.go @@ -17,7 +17,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } func TestDeleteOrganization(t *testing.T) { diff --git a/services/pull/main_test.go b/services/pull/main_test.go index 6059a291addd..5471686e7298 100644 --- a/services/pull/main_test.go +++ b/services/pull/main_test.go @@ -13,5 +13,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/release/release_test.go b/services/release/release_test.go index ec2282d7dbc6..19d985491f15 100644 --- a/services/release/release_test.go +++ b/services/release/release_test.go @@ -21,7 +21,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } func TestRelease_Create(t *testing.T) { diff --git a/services/repository/archiver/archiver_test.go b/services/repository/archiver/archiver_test.go index b7fb6cb0ca40..24437ce76c2c 100644 --- a/services/repository/archiver/archiver_test.go +++ b/services/repository/archiver/archiver_test.go @@ -17,7 +17,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } func TestArchive_Basic(t *testing.T) { diff --git a/services/repository/files/content_test.go b/services/repository/files/content_test.go index 84bb1c2e0292..8a3e589bdf9b 100644 --- a/services/repository/files/content_test.go +++ b/services/repository/files/content_test.go @@ -16,7 +16,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", "..", ".."), + }) } func getExpectedReadmeContentsResponse() *api.ContentsResponse { diff --git a/services/repository/main_test.go b/services/repository/main_test.go index 262d3394818b..42134fa7adab 100644 --- a/services/repository/main_test.go +++ b/services/repository/main_test.go @@ -12,5 +12,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/user/user_test.go b/services/user/user_test.go index 783553039426..cfa02b003311 100644 --- a/services/user/user_test.go +++ b/services/user/user_test.go @@ -20,7 +20,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } func TestDeleteUser(t *testing.T) { diff --git a/services/webhook/main_test.go b/services/webhook/main_test.go index a87b74e89d74..25b9df0af668 100644 --- a/services/webhook/main_test.go +++ b/services/webhook/main_test.go @@ -14,5 +14,7 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go index 17ec657cac59..0c73074dbe27 100644 --- a/services/wiki/wiki_test.go +++ b/services/wiki/wiki_test.go @@ -20,7 +20,9 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } func TestWikiNameToSubURL(t *testing.T) {