mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
test: reduce fixture setup work in Go tests (#40423)
Reduce the work Go tests spend on fixture setup, without dropping any test or covered code. Every fixture repository reset listed and stat'ed both trees, and many packages copied repositories or created a database they never use. - List the fixture repository source tree once per process - Skip the repository copy in DB-only packages and the database in settings-only packages - Drop the unused repository copy and git init from migration tests - Push LFS files last in `TestGitGeneral`, so LFS hooks don't run on every later git command - Link the integration test binary without DWARF Measured locally on macOS, wall and CPU time: | | Before | After | |---|---|---| | Warm fixture repository reset | 127 ms | 63 ms | | 30 affected unit packages | 13.6 s, 72 s CPU | 10.0 s, 51 s CPU | | Migration tests | 29.9 s, 19.1 s CPU | 13.7 s, 8.8 s CPU | | `TestGitGeneral` | 81 s, 69 s CPU | 62 s, 54 s CPU | | 46 API integration tests | 41.7 s | 39.0 s | | Integration test binary relink | 8.7 s, 11.6 s CPU | 3.7 s, 5.7 s CPU | Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
860a2d308b
commit
099abf5db4
37 files changed
+154
-130
No files matched your search
@@ -437,12 +437,12 @@ test-integration: $(EXECUTABLE)
|
||||
@# Use a compiled binary: testlogger forwards gitea logs to t.Log, so `go test -v`
|
||||
@# would flood output per passing test. testcache can't help these tests anyway —
|
||||
@# they mutate the work directory, so cache inputs change between runs.
|
||||
$(GO) test $(GOTEST_FLAGS) -tags '$(TAGS)' -c gitea.dev/tests/integration -o ./test-integration-$(GITEA_TEST_DATABASE).test
|
||||
$(GO) test -ldflags=-w $(GOTEST_FLAGS) -tags '$(TAGS)' -c gitea.dev/tests/integration -o ./test-integration-$(GITEA_TEST_DATABASE).test
|
||||
./tools/test-integration.sh ./test-integration-$(GITEA_TEST_DATABASE).test
|
||||
|
||||
.PHONY: test-integration-compile
|
||||
test-integration-compile:
|
||||
$(GO) test $(GOTEST_FLAGS) -tags '$(TAGS)' -c -o /dev/null gitea.dev/tests/integration
|
||||
$(GO) test -ldflags=-w $(GOTEST_FLAGS) -tags '$(TAGS)' -c -o /dev/null gitea.dev/tests/integration
|
||||
|
||||
TEST_INTEGRATION_GOALS := $(filter test-integration$(HASH)%,$(MAKECMDGOALS))
|
||||
.PHONY: $(TEST_INTEGRATION_GOALS)
|
||||
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/cmd"
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/test"
|
||||
"gitea.dev/modules/util"
|
||||
@@ -26,7 +26,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
setting.SetupGiteaTestEnv()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func makePathOutput(workPath, customPath, customConf string) string {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/models/db" //nolint:depguard // allow to access db in migration tests
|
||||
"gitea.dev/models/unittest" //nolint:depguard // allow to access db in migration tests
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/testlogger"
|
||||
|
||||
@@ -29,8 +28,6 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (base.EngineMigra
|
||||
ourSkip := 2
|
||||
ourSkip += skip
|
||||
deferFn := testlogger.PrintCurrentTest(t, ourSkip)
|
||||
giteaRoot := setting.GetGiteaTestSourceRoot()
|
||||
require.NoError(t, unittest.SyncDirs(filepath.Join(giteaRoot, "tests/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
|
||||
cleanup, err := unittest.ResetTestDatabase()
|
||||
if err != nil {
|
||||
@@ -69,7 +66,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (base.EngineMigra
|
||||
}
|
||||
}
|
||||
|
||||
fixturesDir := filepath.Join(giteaRoot, "modelmigration/fixtures", t.Name())
|
||||
fixturesDir := filepath.Join(setting.GetGiteaTestSourceRoot(), "modelmigration/fixtures", t.Name())
|
||||
|
||||
if _, err := os.Stat(fixturesDir); err == nil {
|
||||
t.Logf("initializing fixtures from: %s", fixturesDir)
|
||||
@@ -110,10 +107,6 @@ func mainTest(m *testing.M) int {
|
||||
return testlogger.MainErrorf("Unable to prepare integration test config: %v", err)
|
||||
}
|
||||
setting.SetupGiteaTestEnv()
|
||||
|
||||
if err = git.InitFull(); err != nil {
|
||||
return testlogger.MainErrorf("Unable to InitFull: %v", err)
|
||||
}
|
||||
setting.Database.SlowQueryThreshold = 0
|
||||
setting.LoadDBSetting()
|
||||
setting.InitLoggersForTest()
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v1_21
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modelmigration/migrationtest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
migrationtest.MainTest(m)
|
||||
}
|
||||
@@ -17,5 +17,6 @@ func TestMain(m *testing.M) {
|
||||
"repository.yml",
|
||||
"user.yml",
|
||||
},
|
||||
SkipRepoFixtures: true,
|
||||
})
|
||||
}
|
||||
@@ -13,5 +13,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -19,5 +19,6 @@ func TestMain(m *testing.M) {
|
||||
"user.yml",
|
||||
"email_address.yml",
|
||||
},
|
||||
SkipRepoFixtures: true,
|
||||
})
|
||||
}
|
||||
@@ -10,5 +10,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -16,5 +16,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -14,5 +14,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -13,5 +13,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package paginator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
@@ -10,5 +10,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -10,5 +10,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{FixtureFiles: []string{}}) // the tests insert what they assert on
|
||||
unittest.MainTest(m, &unittest.TestOptions{FixtureFiles: []string{}, SkipRepoFixtures: true}) // the tests insert what they assert on
|
||||
}
|
||||
@@ -29,5 +29,5 @@ func TestFixturesAreConsistent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -17,5 +17,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
|
||||
func TestHasOwnerPackages(t *testing.T) {
|
||||
|
||||
@@ -16,5 +16,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -19,5 +19,6 @@ func TestMain(m *testing.M) {
|
||||
"project_issue.yml",
|
||||
"repository.yml",
|
||||
},
|
||||
SkipRepoFixtures: true,
|
||||
})
|
||||
}
|
||||
@@ -17,5 +17,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -29,5 +29,5 @@ func TestFixturesAreConsistent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -10,5 +10,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -15,5 +15,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
+44
-35
@@ -8,37 +8,56 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/util"
|
||||
)
|
||||
|
||||
// SyncFile synchronizes the two files. This is skipped if both files
|
||||
// exist and the size, modtime, and mode match.
|
||||
func SyncFile(srcPath, destPath string) error {
|
||||
dest, err := os.Stat(destPath)
|
||||
type syncSource struct {
|
||||
entries []string // util.ListDirRecursively appends a slash to the directory names
|
||||
infos map[string]os.FileInfo
|
||||
}
|
||||
|
||||
var (
|
||||
syncSourcesMu sync.Mutex
|
||||
syncSources = map[string]*syncSource{}
|
||||
)
|
||||
|
||||
func loadSyncSource(srcPath string) (*syncSource, error) {
|
||||
syncSourcesMu.Lock()
|
||||
defer syncSourcesMu.Unlock()
|
||||
if src, ok := syncSources[srcPath]; ok {
|
||||
return src, nil
|
||||
}
|
||||
entries, err := util.ListDirRecursively(srcPath, &util.ListDirOptions{IncludeDir: true})
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return util.CopyFile(srcPath, destPath)
|
||||
return nil, err
|
||||
}
|
||||
src := &syncSource{entries: entries, infos: make(map[string]os.FileInfo, len(entries))}
|
||||
for _, entry := range entries {
|
||||
if src.infos[entry], err = os.Stat(filepath.Join(srcPath, entry)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
syncSources[srcPath] = src
|
||||
return src, nil
|
||||
}
|
||||
|
||||
// syncFile copies the source file unless the destination has the same size, modtime and mode
|
||||
func syncFile(srcInfo os.FileInfo, srcPath, destPath string) error {
|
||||
dest, err := os.Stat(destPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
src, err := os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if src.Size() == dest.Size() &&
|
||||
src.ModTime().Equal(dest.ModTime()) &&
|
||||
src.Mode() == dest.Mode() {
|
||||
if err == nil && srcInfo.Size() == dest.Size() && srcInfo.ModTime().Equal(dest.ModTime()) && srcInfo.Mode() == dest.Mode() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return util.CopyFile(srcPath, destPath)
|
||||
}
|
||||
|
||||
// SyncDirs synchronizes files recursively from source to target directory.
|
||||
// The source directory is only listed once per process, it must not change.
|
||||
// It returns error when error occurs in underlying functions.
|
||||
func SyncDirs(srcPath, destPath string) error {
|
||||
destPath = filepath.Clean(destPath)
|
||||
@@ -54,6 +73,11 @@ func SyncDirs(srcPath, destPath string) error {
|
||||
return errors.New("destination path should not be inside Gitea data directory, otherwise your data for dev mode will be removed")
|
||||
}
|
||||
|
||||
src, err := loadSyncSource(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.MkdirAll(destPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -68,35 +92,20 @@ func SyncDirs(srcPath, destPath string) error {
|
||||
return err
|
||||
}
|
||||
for _, destFile := range destFiles {
|
||||
destFilePath := filepath.Join(destPath, destFile)
|
||||
shouldRemove := filepath.Base(destFilePath) == keepFile
|
||||
if _, err = os.Stat(filepath.Join(srcPath, destFile)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
shouldRemove = true
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// if src file does not exist, remove dest file
|
||||
if shouldRemove {
|
||||
if err = os.RemoveAll(destFilePath); err != nil {
|
||||
if _, ok := src.infos[destFile]; !ok || filepath.Base(destFile) == keepFile {
|
||||
if err = os.RemoveAll(filepath.Join(destPath, destFile)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sync src files to dest
|
||||
srcFiles, err := util.ListDirRecursively(srcPath, &util.ListDirOptions{IncludeDir: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, srcFile := range srcFiles {
|
||||
for _, srcFile := range src.entries {
|
||||
destFilePath := filepath.Join(destPath, srcFile)
|
||||
// util.ListDirRecursively appends a slash to the directory name
|
||||
if strings.HasSuffix(srcFile, "/") {
|
||||
err = os.MkdirAll(destFilePath, os.ModePerm)
|
||||
} else if filepath.Base(destFilePath) != keepFile {
|
||||
err = SyncFile(filepath.Join(srcPath, srcFile), destFilePath)
|
||||
err = syncFile(src.infos[srcFile], filepath.Join(srcPath, srcFile), destFilePath)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package unittest_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSyncDirsRestoresDestination(t *testing.T) {
|
||||
srcPath, destPath := t.TempDir(), t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(srcPath, "dir/sub"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(srcPath, "dir/file"), []byte("content"), 0o644))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(srcPath, "dir/.keep"), nil, 0o644))
|
||||
require.NoError(t, unittest.SyncDirs(srcPath, destPath))
|
||||
|
||||
require.NoError(t, os.WriteFile(filepath.Join(destPath, "dir/file"), []byte("modified content"), 0o644))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(destPath, "extra"), nil, 0o644))
|
||||
require.NoError(t, os.RemoveAll(filepath.Join(destPath, "dir/sub")))
|
||||
require.NoError(t, unittest.SyncDirs(srcPath, destPath))
|
||||
|
||||
entries, err := util.ListDirRecursively(destPath, &util.ListDirOptions{IncludeDir: true})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{"dir/", "dir/file", "dir/sub/"}, entries)
|
||||
content, err := os.ReadFile(filepath.Join(destPath, "dir/file"))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "content", string(content))
|
||||
}
|
||||
@@ -31,9 +31,10 @@ import (
|
||||
|
||||
// TestOptions represents test options
|
||||
type TestOptions struct {
|
||||
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
|
||||
SkipRepoFixtures bool // for packages that never read the fixture git repositories
|
||||
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
|
||||
@@ -79,8 +80,10 @@ func mainTest(m *testing.M, testOptsArg ...*TestOptions) int {
|
||||
if err = storage.Init(); err != nil {
|
||||
return testlogger.MainErrorf("storage.Init: %v", err)
|
||||
}
|
||||
if err = SyncDirs(filepath.Join(giteaRoot, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
|
||||
return testlogger.MainErrorf("util.SyncDirs: %v", err)
|
||||
if !testOpts.SkipRepoFixtures {
|
||||
if err = SyncDirs(filepath.Join(giteaRoot, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
|
||||
return testlogger.MainErrorf("util.SyncDirs: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = git.InitFull(); err != nil {
|
||||
|
||||
@@ -15,5 +15,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -15,5 +15,6 @@ func TestMain(m *testing.M) {
|
||||
"webhook.yml",
|
||||
"hook_task.yml",
|
||||
},
|
||||
SkipRepoFixtures: true,
|
||||
})
|
||||
}
|
||||
@@ -4,21 +4,22 @@
|
||||
package fileicon_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/fileicon"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{FixtureFiles: []string{}})
|
||||
setting.SetupGiteaTestEnv()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestFindIconName(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
p := fileicon.DefaultMaterialIconProvider()
|
||||
assert.Equal(t, "php", p.FindIconName(&fileicon.EntryInfo{BaseName: "foo.php", EntryMode: git.EntryModeBlob}))
|
||||
assert.Equal(t, "php", p.FindIconName(&fileicon.EntryInfo{BaseName: "foo.PHP", EntryMode: git.EntryModeBlob}))
|
||||
|
||||
@@ -166,6 +166,15 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
|
||||
// since there is no refURL, it means that the submodule info doesn't exist, so it won't have a web link
|
||||
assert.Nil(t, cisf.SubmoduleWebLinkTree(t.Context()))
|
||||
})
|
||||
|
||||
t.Run("SubsetOfTreePathEntries", func(t *testing.T) {
|
||||
commit, err := bareRepo1.GetCommit(t.Context(), "37991dec2c8e592043f47155ce4808d4580f9123")
|
||||
require.NoError(t, err)
|
||||
revs, err := GetLastCommitForPaths(t.Context(), bareRepo1, commit, "foo", []string{"bar"})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", revs["bar"].ID.String())
|
||||
assert.NotContains(t, revs, "link_short")
|
||||
})
|
||||
}
|
||||
|
||||
func TestEntries_GetCommitsInfo_ContextErr(t *testing.T) {
|
||||
|
||||
@@ -6,9 +6,9 @@ package install
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/services/contexttest"
|
||||
"gitea.dev/services/forms"
|
||||
@@ -38,7 +38,8 @@ func TestRoutes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
setting.SetupGiteaTestEnv()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestFillInstallConfig(t *testing.T) {
|
||||
|
||||
@@ -23,14 +23,14 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
|
||||
// TestFindColumn covers the scoping rule every board handler depends on: a request only
|
||||
// resolves projects owned by the scope its route assigned, so an ID belonging to anyone
|
||||
// else reads as not found rather than leaking across owners.
|
||||
func TestFindColumn(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
projectID string
|
||||
@@ -69,7 +69,7 @@ func TestFindColumn(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMoveIssuesNeedsOnlyProjectWrite(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, repo_model.UpdateRepositoryColsNoAutoTime(t.Context(), &repo_model.Repository{ID: 3, IsArchived: true}, "is_archived"))
|
||||
ctx, _ := contexttest.MockContext(t, "POST /org3/-/projects")
|
||||
contexttest.LoadUser(t, ctx, 15)
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestChangePassword(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(req.OldPassword+"__"+req.NewPassword, func(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
setting.PasswordComplexity = req.PasswordComplexity
|
||||
ctx, _ := contexttest.MockContext(t, "user/settings/security")
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
|
||||
@@ -10,5 +10,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
unittest.MainTest(m, &unittest.TestOptions{SkipRepoFixtures: true})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package security
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
@@ -4,11 +4,13 @@
|
||||
package sender
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
setting.SetupGiteaTestEnv()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
@@ -81,16 +81,20 @@ func testGitGeneral(t *testing.T, u *url.URL) {
|
||||
|
||||
t.Run("Partial Clone", doPartialGitClone(dstPath2, u))
|
||||
|
||||
pushedFilesStandard := standardCommitAndPushTest(t, dstPath, testFileSizeSmall, testFileSizeLarge)
|
||||
pushedFilesLFS := lfsCommitAndPushTest(t, dstPath, testFileSizeSmall, testFileSizeLarge)
|
||||
rawTest(t, &httpContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1])
|
||||
mediaTest(t, &httpContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1])
|
||||
|
||||
// LFS pushes run after the branch tests, a clone with LFS installed runs its hooks on every later git command
|
||||
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "test/head"))
|
||||
t.Run("CreateProtectedBranch", doCreateProtectedBranch(&httpContext, dstPath))
|
||||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath))
|
||||
t.Run("AutoMerge", doAutoPRMerge(&httpContext, dstPath))
|
||||
t.Run("CreatePRAndSetManuallyMerged", doCreatePRAndSetManuallyMerged(httpContext, httpContext, dstPath, "master", "test-manually-merge"))
|
||||
|
||||
t.Run("CheckoutMaster", doGitCheckoutBranch(dstPath, "master"))
|
||||
t.Run("PullMaster", doGitPull(dstPath, "--ff-only", "origin", "master"))
|
||||
pushedFilesStandard := standardCommitAndPushTest(t, dstPath, testFileSizeSmall, testFileSizeLarge)
|
||||
pushedFilesLFS := lfsCommitAndPushTest(t, dstPath, testFileSizeSmall, testFileSizeLarge)
|
||||
rawTest(t, &httpContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1])
|
||||
mediaTest(t, &httpContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1])
|
||||
|
||||
t.Run("MergeFork", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
t.Run("CreatePRAndMerge", doMergeFork(httpContext, forkedUserCtx, "master", httpContext.Username+":master"))
|
||||
@@ -128,14 +132,17 @@ func testGitGeneral(t *testing.T, u *url.URL) {
|
||||
|
||||
t.Run("Clone", doGitClone(dstPath, sshURL))
|
||||
|
||||
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "test/head2"))
|
||||
t.Run("CreateProtectedBranch", doCreateProtectedBranch(&sshContext, dstPath))
|
||||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
|
||||
|
||||
t.Run("CheckoutMaster", doGitCheckoutBranch(dstPath, "master"))
|
||||
t.Run("PullMaster", doGitPull(dstPath, "--ff-only", "origin", "master"))
|
||||
pushedFilesStandard := standardCommitAndPushTest(t, dstPath, testFileSizeSmall, testFileSizeLarge)
|
||||
pushedFilesLFS := lfsCommitAndPushTest(t, dstPath, testFileSizeSmall, testFileSizeLarge)
|
||||
rawTest(t, &sshContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1])
|
||||
mediaTest(t, &sshContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1])
|
||||
|
||||
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "test/head2"))
|
||||
t.Run("CreateProtectedBranch", doCreateProtectedBranch(&sshContext, dstPath))
|
||||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
|
||||
t.Run("MergeFork", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
t.Run("CreatePRAndMerge", doMergeFork(sshContext, forkedUserCtx, "master", sshContext.Username+":master"))
|
||||
|
||||
Reference in new issue
Block a user