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 <wxiaoguang@gmail.com>
pull/27310/head^2
Lunny Xiao 1 year ago committed by GitHub
parent e74a3b18af
commit 673cf6af76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      cmd/main_test.go
  2. 5
      models/activities/main_test.go
  3. 2
      models/asymkey/main_test.go
  4. 5
      models/auth/main_test.go
  5. 5
      models/avatars/main_test.go
  6. 5
      models/db/main_test.go
  7. 5
      models/db/paginator/main_test.go
  8. 5
      models/dbfs/main_test.go
  9. 5
      models/git/main_test.go
  10. 5
      models/issues/main_test.go
  11. 4
      models/main_test.go
  12. 5
      models/organization/main_test.go
  13. 5
      models/packages/package_test.go
  14. 5
      models/perm/access/main_test.go
  15. 2
      models/project/main_test.go
  16. 5
      models/repo/main_test.go
  17. 5
      models/system/main_test.go
  18. 53
      models/unittest/testdb.go
  19. 5
      models/user/main_test.go
  20. 2
      models/webhook/main_test.go
  21. 5
      modules/activitypub/main_test.go
  22. 5
      modules/indexer/code/indexer_test.go
  23. 5
      modules/indexer/issues/indexer_test.go
  24. 5
      modules/indexer/stats/indexer_test.go
  25. 5
      modules/repository/main_test.go
  26. 4
      modules/system/appstate_test.go
  27. 2
      routers/api/v1/repo/main_test.go
  28. 5
      routers/common/errpage_test.go
  29. 5
      routers/install/routes_test.go
  30. 5
      routers/private/main_test.go
  31. 5
      routers/web/admin/main_test.go
  32. 5
      routers/web/auth/main_test.go
  33. 5
      routers/web/org/main_test.go
  34. 5
      routers/web/repo/main_test.go
  35. 5
      routers/web/repo/setting/main_test.go
  36. 5
      routers/web/user/main_test.go
  37. 5
      routers/web/user/setting/main_test.go
  38. 5
      services/asymkey/main_test.go
  39. 4
      services/attachment/attachment_test.go
  40. 5
      services/convert/main_test.go
  41. 5
      services/feed/action_test.go
  42. 5
      services/gitdiff/main_test.go
  43. 5
      services/issue/main_test.go
  44. 5
      services/mailer/main_test.go
  45. 4
      services/markup/main_test.go
  46. 5
      services/migrations/main_test.go
  47. 5
      services/org/org_test.go
  48. 5
      services/pull/main_test.go
  49. 5
      services/release/release_test.go
  50. 5
      services/repository/archiver/archiver_test.go
  51. 5
      services/repository/files/content_test.go
  52. 5
      services/repository/main_test.go
  53. 5
      services/user/user_test.go
  54. 2
      services/webhook/main_test.go
  55. 5
      services/wiki/wiki_test.go

@ -20,9 +20,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: "..",
})
} }
func makePathOutput(workPath, customPath, customConf string) string { func makePathOutput(workPath, customPath, customConf string) string {

@ -4,7 +4,6 @@
package activities_test package activities_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,7 +13,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package asymkey package asymkey
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -12,7 +11,6 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
FixtureFiles: []string{ FixtureFiles: []string{
"gpg_key.yml", "gpg_key.yml",
"public_key.yml", "public_key.yml",

@ -4,7 +4,6 @@
package auth_test package auth_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -17,7 +16,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package avatars_test package avatars_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -15,7 +14,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package db_test package db_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,7 +13,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,14 +4,11 @@
package paginator package paginator
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package dbfs package dbfs
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package git_test package git_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -15,7 +14,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package issues_test package issues_test
import ( import (
"path/filepath"
"testing" "testing"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
@ -30,7 +29,5 @@ func TestFixturesAreConsistent(t *testing.T) {
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -29,7 +29,5 @@ func TestFixturesAreConsistent(t *testing.T) {
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: "..",
})
} }

@ -4,7 +4,6 @@
package organization_test package organization_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -18,7 +17,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package packages_test package packages_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
@ -20,9 +19,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestHasOwnerPackages(t *testing.T) { func TestHasOwnerPackages(t *testing.T) {

@ -4,7 +4,6 @@
package access_test package access_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -17,7 +16,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,7 +4,6 @@
package project package project
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,7 +13,6 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
FixtureFiles: []string{ FixtureFiles: []string{
"project.yml", "project.yml",
"project_board.yml", "project_board.yml",

@ -4,7 +4,6 @@
package repo_test package repo_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -18,7 +17,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package system_test package system_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -16,7 +15,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -62,35 +62,46 @@ func InitSettings(extraConfigs ...string) {
// TestOptions represents test options // TestOptions represents test options
type TestOptions struct { type TestOptions struct {
GiteaRootPath string FixtureFiles []string
FixtureFiles []string SetUp func() error // SetUp will be executed before all tests in this package
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
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 // MainTest a reusable TestMain(..) function for unit tests that need to use a
// test database. Creates the test database, and sets necessary settings. // test database. Creates the test database, and sets necessary settings.
func MainTest(m *testing.M, testOpts *TestOptions) { func MainTest(m *testing.M, testOpts ...*TestOptions) {
setting.CustomPath = filepath.Join(testOpts.GiteaRootPath, "custom") searchDir, _ := os.Getwd()
InitSettings() for searchDir != "" {
if _, err := os.Stat(filepath.Join(searchDir, "go.mod")); err == nil {
var err error 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 giteaRoot = searchDir
fixturesDir = filepath.Join(testOpts.GiteaRootPath, "models", "fixtures") setting.CustomPath = filepath.Join(giteaRoot, "custom")
InitSettings()
fixturesDir = filepath.Join(giteaRoot, "models", "fixtures")
var opts FixturesOptions var opts FixturesOptions
if len(testOpts.FixtureFiles) == 0 { if len(testOpts) == 0 || len(testOpts[0].FixtureFiles) == 0 {
opts.Dir = fixturesDir opts.Dir = fixturesDir
} else { } else {
for _, f := range testOpts.FixtureFiles { for _, f := range testOpts[0].FixtureFiles {
if len(f) != 0 { if len(f) != 0 {
opts.Files = append(opts.Files, filepath.Join(fixturesDir, f)) 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) fatalTestError("Error creating test engine: %v\n", err)
} }
@ -112,8 +123,8 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
fatalTestError("TempDir: %v\n", err) fatalTestError("TempDir: %v\n", err)
} }
setting.AppDataPath = appDataPath setting.AppDataPath = appDataPath
setting.AppWorkPath = testOpts.GiteaRootPath setting.AppWorkPath = giteaRoot
setting.StaticRootPath = testOpts.GiteaRootPath setting.StaticRootPath = giteaRoot
setting.GravatarSource = "https://secure.gravatar.com/avatar/" setting.GravatarSource = "https://secure.gravatar.com/avatar/"
setting.Attachment.Storage.Path = filepath.Join(setting.AppDataPath, "attachments") 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 { if err = util.RemoveAll(repoRootPath); err != nil {
fatalTestError("util.RemoveAll: %v\n", err) 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) fatalTestError("util.CopyDir: %v\n", err)
} }
@ -171,16 +182,16 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
} }
} }
if testOpts.SetUp != nil { if len(testOpts) > 0 && testOpts[0].SetUp != nil {
if err := testOpts.SetUp(); err != nil { if err := testOpts[0].SetUp(); err != nil {
fatalTestError("set up failed: %v\n", err) fatalTestError("set up failed: %v\n", err)
} }
} }
exitStatus := m.Run() exitStatus := m.Run()
if testOpts.TearDown != nil { if len(testOpts) > 0 && testOpts[0].TearDown != nil {
if err := testOpts.TearDown(); err != nil { if err := testOpts[0].TearDown(); err != nil {
fatalTestError("tear down failed: %v\n", err) fatalTestError("tear down failed: %v\n", err)
} }
} }

@ -4,7 +4,6 @@
package user_test package user_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -16,7 +15,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package webhook package webhook
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -12,7 +11,6 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
FixtureFiles: []string{ FixtureFiles: []string{
"webhook.yml", "webhook.yml",
"hook_task.yml", "hook_task.yml",

@ -4,7 +4,6 @@
package activitypub package activitypub
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -15,7 +14,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -6,7 +6,6 @@ package code
import ( import (
"context" "context"
"os" "os"
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -23,9 +22,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }
func testIndexer(name string, t *testing.T, indexer internal.Indexer) { func testIndexer(name string, t *testing.T, indexer internal.Indexer) {

@ -5,7 +5,6 @@ package issues
import ( import (
"context" "context"
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
@ -22,9 +21,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }
func TestDBSearchIssues(t *testing.T) { func TestDBSearchIssues(t *testing.T) {

@ -5,7 +5,6 @@ package stats
import ( import (
"context" "context"
"path/filepath"
"testing" "testing"
"time" "time"
@ -23,9 +22,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }
func TestRepoStatsIndex(t *testing.T) { func TestRepoStatsIndex(t *testing.T) {

@ -4,7 +4,6 @@
package repository package repository
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -13,7 +12,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package system package system
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,8 +13,7 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."), FixtureFiles: []string{""}, // load nothing
FixtureFiles: []string{""}, // load nothing
}) })
} }

@ -4,7 +4,6 @@
package repo package repo
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,7 +13,6 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", "..", "..", ".."),
SetUp: func() error { SetUp: func() error {
setting.LoadQueueSettings() setting.LoadQueueSettings()
return webhook_service.Init() return webhook_service.Init()

@ -9,7 +9,6 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -35,7 +34,5 @@ func TestRenderPanicErrorPage(t *testing.T) {
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -5,7 +5,6 @@ package install
import ( import (
"net/http/httptest" "net/http/httptest"
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -35,7 +34,5 @@ func TestRoutes(t *testing.T) {
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,14 +4,11 @@
package private package private
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,14 +4,11 @@
package admin package admin
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package auth package auth
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package org_test package org_test
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package repo package repo
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package setting package setting
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package user package user
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }

@ -4,14 +4,11 @@
package setting package setting
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", "..", ".."),
})
} }

@ -4,7 +4,6 @@
package asymkey package asymkey
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,7 +13,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -19,9 +19,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestUploadAttachment(t *testing.T) { func TestUploadAttachment(t *testing.T) {

@ -4,7 +4,6 @@
package convert package convert
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -13,7 +12,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package feed package feed
import ( import (
"path/filepath"
"strings" "strings"
"testing" "testing"
@ -20,9 +19,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestRenameRepoAction(t *testing.T) { func TestRenameRepoAction(t *testing.T) {

@ -4,7 +4,6 @@
package gitdiff package gitdiff
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -15,7 +14,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package issue package issue
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -13,7 +12,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package mailer package mailer
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -13,7 +12,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package markup package markup
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -12,7 +11,6 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."), FixtureFiles: []string{"user.yml"},
FixtureFiles: []string{"user.yml"},
}) })
} }

@ -5,7 +5,6 @@
package migrations package migrations
import ( import (
"path/filepath"
"testing" "testing"
"time" "time"
@ -16,9 +15,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func timePtr(t time.Time) *time.Time { func timePtr(t time.Time) *time.Time {

@ -4,7 +4,6 @@
package org package org
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@ -16,9 +15,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestDeleteOrganization(t *testing.T) { func TestDeleteOrganization(t *testing.T) {

@ -5,7 +5,6 @@
package pull package pull
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -14,7 +13,5 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -4,7 +4,6 @@
package release package release
import ( import (
"path/filepath"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -22,9 +21,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestRelease_Create(t *testing.T) { func TestRelease_Create(t *testing.T) {

@ -5,7 +5,6 @@ package archiver
import ( import (
"errors" "errors"
"path/filepath"
"testing" "testing"
"time" "time"
@ -18,9 +17,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }
func TestArchive_Basic(t *testing.T) { func TestArchive_Basic(t *testing.T) {

@ -4,7 +4,6 @@
package files package files
import ( import (
"path/filepath"
"testing" "testing"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
@ -19,9 +18,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", "..", ".."),
})
} }
func getExpectedReadmeContentsResponse() *api.ContentsResponse { func getExpectedReadmeContentsResponse() *api.ContentsResponse {

@ -4,14 +4,11 @@
package repository package repository
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }

@ -5,7 +5,6 @@ package user
import ( import (
"fmt" "fmt"
"path/filepath"
"strings" "strings"
"testing" "testing"
@ -22,9 +21,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestDeleteUser(t *testing.T) { func TestDeleteUser(t *testing.T) {

@ -4,7 +4,6 @@
package webhook package webhook
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
@ -19,7 +18,6 @@ func TestMain(m *testing.M) {
// for tests, allow only loopback IPs // for tests, allow only loopback IPs
setting.Webhook.AllowedHostList = hostmatcher.MatchBuiltinLoopback setting.Webhook.AllowedHostList = hostmatcher.MatchBuiltinLoopback
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
SetUp: func() error { SetUp: func() error {
setting.LoadQueueSettings() setting.LoadQueueSettings()
return Init() return Init()

@ -5,7 +5,6 @@ package wiki
import ( import (
"math/rand" "math/rand"
"path/filepath"
"strings" "strings"
"testing" "testing"
@ -20,9 +19,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m)
GiteaRootPath: filepath.Join("..", ".."),
})
} }
func TestWebPathSegments(t *testing.T) { func TestWebPathSegments(t *testing.T) {

Loading…
Cancel
Save