From 68731c07c52d35b7b44db1c2f5f7a755efcc8c84 Mon Sep 17 00:00:00 2001 From: Rowan Bohde Date: Thu, 14 Nov 2024 13:28:46 -0600 Subject: [PATCH] Reduce integration test overhead (#32475) In profiling integration tests, I found a couple places where per-test overhead could be reduced: * Avoiding disk IO by synchronizing instead of deleting & copying test Git repository data. This saves ~100ms per test on my machine * When flushing queues in `PrintCurrentTest`, invoke `FlushWithContext` in a parallel. --------- Co-authored-by: wxiaoguang --- models/fixtures/repository.yml | 2 +- models/migrations/base/tests.go | 31 ++----- models/unittest/fscopy.go | 84 ++++++++++--------- models/unittest/testdb.go | 45 +--------- .../repos/language_stats_repo/description | 1 - .../repos/language_stats_repo/info/exclude | 6 -- .../git/tests/repos/repo1_bare/description | 1 - .../git/tests/repos/repo1_bare/info/exclude | 6 -- .../tests/repos/repo1_bare_sha256/description | 1 - .../repos/repo1_bare_sha256/info/exclude | 6 -- .../git/tests/repos/repo2_empty/description | 1 - .../git/tests/repos/repo2_empty/info/exclude | 6 -- .../git/tests/repos/repo3_notes/description | 1 - .../git/tests/repos/repo5_pulls/description | 1 - .../git/tests/repos/repo5_pulls/info/exclude | 6 -- .../repos/repo5_pulls_sha256/description | 1 - .../repos/repo6_blame_sha256/description | 1 - .../repos/repo6_blame_sha256/info/exclude | 6 -- .../repos/repo6_merge_sha256/description | 1 - .../repos/repo6_merge_sha256/info/exclude | 6 -- modules/indexer/code/indexer_test.go | 11 +-- modules/queue/manager.go | 9 +- modules/queue/workergroup.go | 19 ++++- modules/queue/workerqueue.go | 11 ++- modules/repository/create_test.go | 4 +- modules/testlogger/testlogger.go | 2 +- .../testdata/academic-module/description | 1 - .../testdata/academic-module/info/exclude | 6 -- services/repository/adopt_test.go | 2 +- .../description | 1 - .../info/exclude | 6 -- .../description | 1 - .../info/exclude | 6 -- .../migration/lfs-test.git/description | 1 - .../repo_external_tracker.git/description | 1 - .../repo_external_tracker.git/info/exclude | 6 -- .../description | 1 - .../info/exclude | 6 -- .../description | 1 - .../info/exclude | 6 -- .../org3/repo3.git/description | 1 - .../org3/repo3.git/info/exclude | 6 -- .../org3/repo5.git/description | 1 - .../org3/repo5.git/info/exclude | 6 -- .../org41/repo61.git/description | 1 - .../org41/repo61.git/info/exclude | 6 -- .../org41/repo61.git/objects/.keep | 0 .../org41/repo61.git/refs/.keep | 0 .../org42/search-by-path.git/info/exclude | 6 -- .../org42/search-by-path.git/refs/.keep | 0 .../description | 1 - .../info/exclude | 6 -- .../description | 1 - .../info/exclude | 6 -- .../user12/repo10.git/description | 1 - .../user12/repo10.git/info/exclude | 6 -- .../user13/repo11.git/description | 1 - .../user13/repo11.git/info/exclude | 6 -- .../user2/commits_search_test.git/description | 1 - .../commits_search_test.git/info/exclude | 6 -- .../user2/commitsonpr.git/description | 1 - .../user2/commitsonpr.git/info/exclude | 6 -- .../user2/git_hooks_test.git/description | 1 - .../user2/git_hooks_test.git/info/exclude | 6 -- .../user2/glob.git/description | 1 - .../user2/glob.git/info/exclude | 6 -- .../user2/readme-test.git/info/exclude | 6 -- .../user2/repo-release.git/description | 1 - .../user2/repo-release.git/info/exclude | 6 -- .../user2/repo1.git/description | 1 - .../user2/repo1.git/info/exclude | 6 -- .../user2/repo1.wiki.git/description | 1 - .../user2/repo1.wiki.git/info/exclude | 6 -- .../user2/repo15.git/description | 1 - .../user2/repo15.git/info/exclude | 6 -- .../user2/repo16.git/description | 1 - .../user2/repo16.git/info/exclude | 6 -- .../user2/repo2.git/description | 1 - .../user2/repo2.git/info/exclude | 6 -- .../user2/repo20.git/description | 1 - .../user2/repo20.git/info/exclude | 6 -- .../user2/test_commit_revert.git/description | 1 - .../user2/test_commit_revert.git/info/exclude | 6 -- .../user2/utf8.git/description | 1 - .../user2/utf8.git/info/exclude | 6 -- .../user27/repo49.git/description | 1 - .../user27/repo49.git/info/exclude | 6 -- .../user27/template1.git/description | 1 - .../user27/template1.git/info/exclude | 6 -- .../user30/empty.git/objects/.keep | 0 .../user30/empty.git/refs/.keep | 0 .../user30/renderer.git/info/exclude | 6 -- .../user30/renderer.git/refs/.keep | 0 .../user40/repo60.git/description | 1 - .../user40/repo60.git/info/exclude | 6 -- .../user40/repo60.git/objects/.keep | 0 .../user40/repo60.git/refs/.keep | 0 .../user5/repo4.git/description | 1 - .../user5/repo4.git/info/exclude | 6 -- tests/integration/integration_test.go | 3 +- .../migration-test/migration_test.go | 23 +---- tests/test_utils.go | 25 +----- 102 files changed, 95 insertions(+), 456 deletions(-) delete mode 100644 modules/git/tests/repos/language_stats_repo/description delete mode 100644 modules/git/tests/repos/language_stats_repo/info/exclude delete mode 100644 modules/git/tests/repos/repo1_bare/description delete mode 100644 modules/git/tests/repos/repo1_bare/info/exclude delete mode 100644 modules/git/tests/repos/repo1_bare_sha256/description delete mode 100644 modules/git/tests/repos/repo1_bare_sha256/info/exclude delete mode 100644 modules/git/tests/repos/repo2_empty/description delete mode 100644 modules/git/tests/repos/repo2_empty/info/exclude delete mode 100644 modules/git/tests/repos/repo3_notes/description delete mode 100644 modules/git/tests/repos/repo5_pulls/description delete mode 100644 modules/git/tests/repos/repo5_pulls/info/exclude delete mode 100644 modules/git/tests/repos/repo5_pulls_sha256/description delete mode 100644 modules/git/tests/repos/repo6_blame_sha256/description delete mode 100644 modules/git/tests/repos/repo6_blame_sha256/info/exclude delete mode 100644 modules/git/tests/repos/repo6_merge_sha256/description delete mode 100644 modules/git/tests/repos/repo6_merge_sha256/info/exclude delete mode 100644 services/gitdiff/testdata/academic-module/description delete mode 100644 services/gitdiff/testdata/academic-module/info/exclude delete mode 100644 tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/description delete mode 100644 tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/description delete mode 100644 tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/migration/lfs-test.git/description delete mode 100644 tests/gitea-repositories-meta/org26/repo_external_tracker.git/description delete mode 100644 tests/gitea-repositories-meta/org26/repo_external_tracker.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/description delete mode 100644 tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/description delete mode 100644 tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/org3/repo3.git/description delete mode 100644 tests/gitea-repositories-meta/org3/repo3.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/org3/repo5.git/description delete mode 100644 tests/gitea-repositories-meta/org3/repo5.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/org41/repo61.git/description delete mode 100644 tests/gitea-repositories-meta/org41/repo61.git/info/exclude create mode 100644 tests/gitea-repositories-meta/org41/repo61.git/objects/.keep create mode 100644 tests/gitea-repositories-meta/org41/repo61.git/refs/.keep delete mode 100644 tests/gitea-repositories-meta/org42/search-by-path.git/info/exclude create mode 100644 tests/gitea-repositories-meta/org42/search-by-path.git/refs/.keep delete mode 100644 tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/description delete mode 100644 tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/description delete mode 100644 tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user12/repo10.git/description delete mode 100644 tests/gitea-repositories-meta/user12/repo10.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user13/repo11.git/description delete mode 100644 tests/gitea-repositories-meta/user13/repo11.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/commits_search_test.git/description delete mode 100644 tests/gitea-repositories-meta/user2/commits_search_test.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/commitsonpr.git/description delete mode 100644 tests/gitea-repositories-meta/user2/commitsonpr.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/git_hooks_test.git/description delete mode 100644 tests/gitea-repositories-meta/user2/git_hooks_test.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/glob.git/description delete mode 100644 tests/gitea-repositories-meta/user2/glob.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/readme-test.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo-release.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo-release.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo1.wiki.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo1.wiki.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo15.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo15.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo16.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo16.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo2.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo2.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/repo20.git/description delete mode 100644 tests/gitea-repositories-meta/user2/repo20.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/test_commit_revert.git/description delete mode 100644 tests/gitea-repositories-meta/user2/test_commit_revert.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user2/utf8.git/description delete mode 100644 tests/gitea-repositories-meta/user2/utf8.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user27/repo49.git/description delete mode 100644 tests/gitea-repositories-meta/user27/repo49.git/info/exclude delete mode 100644 tests/gitea-repositories-meta/user27/template1.git/description delete mode 100644 tests/gitea-repositories-meta/user27/template1.git/info/exclude create mode 100644 tests/gitea-repositories-meta/user30/empty.git/objects/.keep create mode 100644 tests/gitea-repositories-meta/user30/empty.git/refs/.keep delete mode 100644 tests/gitea-repositories-meta/user30/renderer.git/info/exclude create mode 100644 tests/gitea-repositories-meta/user30/renderer.git/refs/.keep delete mode 100644 tests/gitea-repositories-meta/user40/repo60.git/description delete mode 100644 tests/gitea-repositories-meta/user40/repo60.git/info/exclude create mode 100644 tests/gitea-repositories-meta/user40/repo60.git/objects/.keep create mode 100644 tests/gitea-repositories-meta/user40/repo60.git/refs/.keep delete mode 100644 tests/gitea-repositories-meta/user5/repo4.git/description delete mode 100644 tests/gitea-repositories-meta/user5/repo4.git/info/exclude diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index b7970cb7c8..bbb028eb7b 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -26,7 +26,7 @@ fork_id: 0 is_template: false template_id: 0 - size: 8478 + size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false diff --git a/models/migrations/base/tests.go b/models/migrations/base/tests.go index 85cafc1ab9..95d8f07934 100644 --- a/models/migrations/base/tests.go +++ b/models/migrations/base/tests.go @@ -8,7 +8,6 @@ import ( "context" "fmt" "os" - "path" "path/filepath" "runtime" "testing" @@ -35,27 +34,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu ourSkip := 2 ourSkip += skip deferFn := testlogger.PrintCurrentTest(t, ourSkip) - assert.NoError(t, os.RemoveAll(setting.RepoRootPath)) - assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) - ownerDirs, err := os.ReadDir(setting.RepoRootPath) - if err != nil { - assert.NoError(t, err, "unable to read the new repo root: %v\n", err) - } - for _, ownerDir := range ownerDirs { - if !ownerDir.Type().IsDir() { - continue - } - repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name())) - if err != nil { - assert.NoError(t, err, "unable to read the new repo root: %v\n", err) - } - for _, repoDir := range repoDirs { - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755) - } - } + assert.NoError(t, unittest.SyncDirs(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) if err := deleteDB(); err != nil { t.Errorf("unable to reset database: %v", err) @@ -123,7 +102,7 @@ func MainTest(m *testing.M) { if runtime.GOOS == "windows" { giteaBinary += ".exe" } - setting.AppPath = path.Join(giteaRoot, giteaBinary) + setting.AppPath = filepath.Join(giteaRoot, giteaBinary) if _, err := os.Stat(setting.AppPath); err != nil { fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath) os.Exit(1) @@ -131,12 +110,12 @@ func MainTest(m *testing.M) { giteaConf := os.Getenv("GITEA_CONF") if giteaConf == "" { - giteaConf = path.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini") + giteaConf = filepath.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini") fmt.Printf("Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf) } - if !path.IsAbs(giteaConf) { - setting.CustomConf = path.Join(giteaRoot, giteaConf) + if !filepath.IsAbs(giteaConf) { + setting.CustomConf = filepath.Join(giteaRoot, giteaConf) } else { setting.CustomConf = giteaConf } diff --git a/models/unittest/fscopy.go b/models/unittest/fscopy.go index 74b12d5057..4d7ee2151d 100644 --- a/models/unittest/fscopy.go +++ b/models/unittest/fscopy.go @@ -4,10 +4,8 @@ package unittest import ( - "errors" - "io" "os" - "path" + "path/filepath" "strings" "code.gitea.io/gitea/modules/util" @@ -32,67 +30,73 @@ func Copy(src, dest string) error { return os.Symlink(target, dest) } - sr, err := os.Open(src) + return util.CopyFile(src, dest) +} + +// Sync synchronizes the two files. This is skipped if both files +// exist and the size, modtime, and mode match. +func Sync(srcPath, destPath string) error { + dest, err := os.Stat(destPath) if err != nil { + if os.IsNotExist(err) { + return Copy(srcPath, destPath) + } return err } - defer sr.Close() - dw, err := os.Create(dest) + src, err := os.Stat(srcPath) if err != nil { return err } - defer dw.Close() - if _, err = io.Copy(dw, sr); err != nil { - return err + if src.Size() == dest.Size() && + src.ModTime() == dest.ModTime() && + src.Mode() == dest.Mode() { + return nil } - // Set back file information. - if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil { - return err - } - return os.Chmod(dest, si.Mode()) + return Copy(srcPath, destPath) } -// CopyDir copy files recursively from source to target directory. -// -// The filter accepts a function that process the path info. -// and should return true for need to filter. -// +// SyncDirs synchronizes files recursively from source to target directory. // It returns error when error occurs in underlying functions. -func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error { - // Check if target directory exists. - if _, err := os.Stat(destPath); !errors.Is(err, os.ErrNotExist) { - return util.NewAlreadyExistErrorf("file or directory already exists: %s", destPath) - } - +func SyncDirs(srcPath, destPath string) error { err := os.MkdirAll(destPath, os.ModePerm) if err != nil { return err } - // Gather directory info. - infos, err := util.StatDir(srcPath, true) + // find and delete all untracked files + destFiles, err := util.StatDir(destPath, true) if err != nil { return err } - - var filter func(filePath string) bool - if len(filters) > 0 { - filter = filters[0] - } - - for _, info := range infos { - if filter != nil && filter(info) { - continue + for _, destFile := range destFiles { + destFilePath := filepath.Join(destPath, destFile) + if _, err = os.Stat(filepath.Join(srcPath, destFile)); err != nil { + if os.IsNotExist(err) { + // if src file does not exist, remove dest file + if err = os.RemoveAll(destFilePath); err != nil { + return err + } + } else { + return err + } } + } - curPath := path.Join(destPath, info) - if strings.HasSuffix(info, "/") { - err = os.MkdirAll(curPath, os.ModePerm) + // sync src files to dest + srcFiles, err := util.StatDir(srcPath, true) + if err != nil { + return err + } + for _, srcFile := range srcFiles { + destFilePath := filepath.Join(destPath, srcFile) + // util.StatDir appends a slash to the directory name + if strings.HasSuffix(srcFile, "/") { + err = os.MkdirAll(destFilePath, os.ModePerm) } else { - err = Copy(path.Join(srcPath, info), curPath) + err = Sync(filepath.Join(srcPath, srcFile), destFilePath) } if err != nil { return err diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go index 53c9dbdd77..5a1c27dbea 100644 --- a/models/unittest/testdb.go +++ b/models/unittest/testdb.go @@ -164,35 +164,13 @@ func MainTest(m *testing.M, testOpts ...*TestOptions) { if err = storage.Init(); err != nil { fatalTestError("storage.Init: %v\n", err) } - if err = util.RemoveAll(repoRootPath); err != nil { - fatalTestError("util.RemoveAll: %v\n", err) - } - if err = CopyDir(filepath.Join(giteaRoot, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil { - fatalTestError("util.CopyDir: %v\n", err) + if err = SyncDirs(filepath.Join(giteaRoot, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil { + fatalTestError("util.SyncDirs: %v\n", err) } if err = git.InitFull(context.Background()); err != nil { fatalTestError("git.Init: %v\n", err) } - ownerDirs, err := os.ReadDir(setting.RepoRootPath) - if err != nil { - fatalTestError("unable to read the new repo root: %v\n", err) - } - for _, ownerDir := range ownerDirs { - if !ownerDir.Type().IsDir() { - continue - } - repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name())) - if err != nil { - fatalTestError("unable to read the new repo root: %v\n", err) - } - for _, repoDir := range repoDirs { - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755) - } - } if len(testOpts) > 0 && testOpts[0].SetUp != nil { if err := testOpts[0].SetUp(); err != nil { @@ -255,24 +233,7 @@ func PrepareTestDatabase() error { // by tests that use the above MainTest(..) function. func PrepareTestEnv(t testing.TB) { assert.NoError(t, PrepareTestDatabase()) - assert.NoError(t, util.RemoveAll(setting.RepoRootPath)) metaPath := filepath.Join(giteaRoot, "tests", "gitea-repositories-meta") - assert.NoError(t, CopyDir(metaPath, setting.RepoRootPath)) - ownerDirs, err := os.ReadDir(setting.RepoRootPath) - assert.NoError(t, err) - for _, ownerDir := range ownerDirs { - if !ownerDir.Type().IsDir() { - continue - } - repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name())) - assert.NoError(t, err) - for _, repoDir := range repoDirs { - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755) - } - } - + assert.NoError(t, SyncDirs(metaPath, setting.RepoRootPath)) base.SetupGiteaRoot() // Makes sure GITEA_ROOT is set } diff --git a/modules/git/tests/repos/language_stats_repo/description b/modules/git/tests/repos/language_stats_repo/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/language_stats_repo/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/language_stats_repo/info/exclude b/modules/git/tests/repos/language_stats_repo/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/language_stats_repo/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/git/tests/repos/repo1_bare/description b/modules/git/tests/repos/repo1_bare/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo1_bare/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo1_bare/info/exclude b/modules/git/tests/repos/repo1_bare/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/repo1_bare/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/git/tests/repos/repo1_bare_sha256/description b/modules/git/tests/repos/repo1_bare_sha256/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo1_bare_sha256/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo1_bare_sha256/info/exclude b/modules/git/tests/repos/repo1_bare_sha256/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/repo1_bare_sha256/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/git/tests/repos/repo2_empty/description b/modules/git/tests/repos/repo2_empty/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo2_empty/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo2_empty/info/exclude b/modules/git/tests/repos/repo2_empty/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/repo2_empty/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/git/tests/repos/repo3_notes/description b/modules/git/tests/repos/repo3_notes/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo3_notes/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo5_pulls/description b/modules/git/tests/repos/repo5_pulls/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo5_pulls/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo5_pulls/info/exclude b/modules/git/tests/repos/repo5_pulls/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/repo5_pulls/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/git/tests/repos/repo5_pulls_sha256/description b/modules/git/tests/repos/repo5_pulls_sha256/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo5_pulls_sha256/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo6_blame_sha256/description b/modules/git/tests/repos/repo6_blame_sha256/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo6_blame_sha256/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo6_blame_sha256/info/exclude b/modules/git/tests/repos/repo6_blame_sha256/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/repo6_blame_sha256/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/git/tests/repos/repo6_merge_sha256/description b/modules/git/tests/repos/repo6_merge_sha256/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/modules/git/tests/repos/repo6_merge_sha256/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo6_merge_sha256/info/exclude b/modules/git/tests/repos/repo6_merge_sha256/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/modules/git/tests/repos/repo6_merge_sha256/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go index 020ccc72f8..78fbe7f792 100644 --- a/modules/indexer/code/indexer_test.go +++ b/modules/indexer/code/indexer_test.go @@ -21,6 +21,7 @@ import ( _ "code.gitea.io/gitea/models/activities" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" _ "github.com/mattn/go-sqlite3" ) @@ -284,15 +285,11 @@ func TestBleveIndexAndSearch(t *testing.T) { dir := t.TempDir() idx := bleve.NewIndexer(dir) - _, err := idx.Init(context.Background()) - if err != nil { - if idx != nil { - idx.Close() - } - assert.FailNow(t, "Unable to create bleve indexer Error: %v", err) - } defer idx.Close() + _, err := idx.Init(context.Background()) + require.NoError(t, err) + testIndexer("beleve", t, idx) } diff --git a/modules/queue/manager.go b/modules/queue/manager.go index 8b964c0c28..079e2bee7a 100644 --- a/modules/queue/manager.go +++ b/modules/queue/manager.go @@ -5,6 +5,7 @@ package queue import ( "context" + "errors" "sync" "time" @@ -32,6 +33,7 @@ type ManagedWorkerPoolQueue interface { // FlushWithContext tries to make the handler process all items in the queue synchronously. // It is for testing purpose only. It's not designed to be used in a cluster. + // Negative timeout means discarding all items in the queue. FlushWithContext(ctx context.Context, timeout time.Duration) error // RemoveAllItems removes all items in the base queue (on-the-fly items are not affected) @@ -76,15 +78,16 @@ func (m *Manager) ManagedQueues() map[int64]ManagedWorkerPoolQueue { // FlushAll tries to make all managed queues process all items synchronously, until timeout or the queue is empty. // It is for testing purpose only. It's not designed to be used in a cluster. +// Negative timeout means discarding all items in the queue. func (m *Manager) FlushAll(ctx context.Context, timeout time.Duration) error { - var finalErr error + var finalErrors []error qs := m.ManagedQueues() for _, q := range qs { if err := q.FlushWithContext(ctx, timeout); err != nil { - finalErr = err // TODO: in Go 1.20: errors.Join + finalErrors = append(finalErrors, err) } } - return finalErr + return errors.Join(finalErrors...) } // CreateSimpleQueue creates a simple queue from global setting config provider by name diff --git a/modules/queue/workergroup.go b/modules/queue/workergroup.go index 153123f883..5859b64c0d 100644 --- a/modules/queue/workergroup.go +++ b/modules/queue/workergroup.go @@ -197,15 +197,30 @@ func (q *WorkerPoolQueue[T]) doFlush(wg *workerGroup[T], flush flushType) { defer log.Debug("Queue %q finishes flushing", q.GetName()) // stop all workers, and prepare a new worker context to start new workers - wg.ctxWorkerCancel() wg.wg.Wait() defer func() { - close(flush) + close(flush.c) wg.doPrepareWorkerContext() }() + if flush.timeout < 0 { + // discard everything + wg.batchBuffer = nil + for { + select { + case <-wg.popItemChan: + case <-wg.popItemErr: + case <-q.batchChan: + case <-q.ctxRun.Done(): + return + default: + return + } + } + } + // drain the batch channel first loop: for { diff --git a/modules/queue/workerqueue.go b/modules/queue/workerqueue.go index b28fd88027..f35ed93239 100644 --- a/modules/queue/workerqueue.go +++ b/modules/queue/workerqueue.go @@ -42,7 +42,10 @@ type WorkerPoolQueue[T any] struct { workerNumMu sync.Mutex } -type flushType chan struct{} +type flushType struct { + timeout time.Duration + c chan struct{} +} var _ ManagedWorkerPoolQueue = (*WorkerPoolQueue[any])(nil) @@ -104,12 +107,12 @@ func (q *WorkerPoolQueue[T]) FlushWithContext(ctx context.Context, timeout time. if timeout > 0 { after = time.After(timeout) } - c := make(flushType) + flush := flushType{timeout: timeout, c: make(chan struct{})} // send flush request // if it blocks, it means that there is a flush in progress or the queue hasn't been started yet select { - case q.flushChan <- c: + case q.flushChan <- flush: case <-ctx.Done(): return ctx.Err() case <-q.ctxRun.Done(): @@ -120,7 +123,7 @@ func (q *WorkerPoolQueue[T]) FlushWithContext(ctx context.Context, timeout time. // wait for flush to finish select { - case <-c: + case <-flush.c: return nil case <-ctx.Done(): return ctx.Err() diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go index 6a2f4deaff..a9151482b4 100644 --- a/modules/repository/create_test.go +++ b/modules/repository/create_test.go @@ -38,8 +38,8 @@ func TestGetDirectorySize(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 1) assert.NoError(t, err) - size, err := getDirectorySize(repo.RepoPath()) assert.NoError(t, err) - assert.EqualValues(t, size, repo.Size) + repo.Size = 8165 // real size on the disk + assert.EqualValues(t, repo.Size, size) } diff --git a/modules/testlogger/testlogger.go b/modules/testlogger/testlogger.go index 9a54d63f20..2bc3984ed6 100644 --- a/modules/testlogger/testlogger.go +++ b/modules/testlogger/testlogger.go @@ -118,7 +118,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) func() { _, _ = fmt.Fprintf(os.Stdout, "+++ %s ... still flushing after %v ...\n", t.Name(), SlowFlush) } }) - if err := queue.GetManager().FlushAll(context.Background(), time.Minute); err != nil { + if err := queue.GetManager().FlushAll(context.Background(), -1); err != nil { t.Errorf("Flushing queues failed with error %v", err) } timer.Stop() diff --git a/services/gitdiff/testdata/academic-module/description b/services/gitdiff/testdata/academic-module/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/services/gitdiff/testdata/academic-module/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/services/gitdiff/testdata/academic-module/info/exclude b/services/gitdiff/testdata/academic-module/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/services/gitdiff/testdata/academic-module/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go index 38949c7602..123cedc1f2 100644 --- a/services/repository/adopt_test.go +++ b/services/repository/adopt_test.go @@ -89,7 +89,7 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) { func TestAdoptRepository(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - assert.NoError(t, unittest.CopyDir(filepath.Join(setting.RepoRootPath, "user2", "repo1.git"), filepath.Join(setting.RepoRootPath, "user2", "test-adopt.git"))) + assert.NoError(t, unittest.SyncDirs(filepath.Join(setting.RepoRootPath, "user2", "repo1.git"), filepath.Join(setting.RepoRootPath, "user2", "test-adopt.git"))) user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) _, err := AdoptRepository(db.DefaultContext, user2, user2, CreateRepoOptions{Name: "test-adopt"}) assert.NoError(t, err) diff --git a/tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/description b/tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/info/exclude b/tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/limited_org/private_repo_on_limited_org.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/description b/tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/info/exclude b/tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/limited_org/public_repo_on_limited_org.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/migration/lfs-test.git/description b/tests/gitea-repositories-meta/migration/lfs-test.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/migration/lfs-test.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org26/repo_external_tracker.git/description b/tests/gitea-repositories-meta/org26/repo_external_tracker.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/org26/repo_external_tracker.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org26/repo_external_tracker.git/info/exclude b/tests/gitea-repositories-meta/org26/repo_external_tracker.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org26/repo_external_tracker.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/description b/tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/info/exclude b/tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org26/repo_external_tracker_alpha.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/description b/tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/info/exclude b/tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org26/repo_external_tracker_numeric.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org3/repo3.git/description b/tests/gitea-repositories-meta/org3/repo3.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/org3/repo3.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org3/repo3.git/info/exclude b/tests/gitea-repositories-meta/org3/repo3.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org3/repo3.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org3/repo5.git/description b/tests/gitea-repositories-meta/org3/repo5.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/org3/repo5.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org3/repo5.git/info/exclude b/tests/gitea-repositories-meta/org3/repo5.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org3/repo5.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org41/repo61.git/description b/tests/gitea-repositories-meta/org41/repo61.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/org41/repo61.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/org41/repo61.git/info/exclude b/tests/gitea-repositories-meta/org41/repo61.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org41/repo61.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org41/repo61.git/objects/.keep b/tests/gitea-repositories-meta/org41/repo61.git/objects/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/org41/repo61.git/refs/.keep b/tests/gitea-repositories-meta/org41/repo61.git/refs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/org42/search-by-path.git/info/exclude b/tests/gitea-repositories-meta/org42/search-by-path.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/org42/search-by-path.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/org42/search-by-path.git/refs/.keep b/tests/gitea-repositories-meta/org42/search-by-path.git/refs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/description b/tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/info/exclude b/tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/privated_org/private_repo_on_private_org.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/description b/tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/info/exclude b/tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/privated_org/public_repo_on_private_org.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user12/repo10.git/description b/tests/gitea-repositories-meta/user12/repo10.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user12/repo10.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user12/repo10.git/info/exclude b/tests/gitea-repositories-meta/user12/repo10.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user12/repo10.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user13/repo11.git/description b/tests/gitea-repositories-meta/user13/repo11.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user13/repo11.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user13/repo11.git/info/exclude b/tests/gitea-repositories-meta/user13/repo11.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user13/repo11.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/commits_search_test.git/description b/tests/gitea-repositories-meta/user2/commits_search_test.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/commits_search_test.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/commits_search_test.git/info/exclude b/tests/gitea-repositories-meta/user2/commits_search_test.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/commits_search_test.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/commitsonpr.git/description b/tests/gitea-repositories-meta/user2/commitsonpr.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/commitsonpr.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/commitsonpr.git/info/exclude b/tests/gitea-repositories-meta/user2/commitsonpr.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/commitsonpr.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/git_hooks_test.git/description b/tests/gitea-repositories-meta/user2/git_hooks_test.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/git_hooks_test.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/git_hooks_test.git/info/exclude b/tests/gitea-repositories-meta/user2/git_hooks_test.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/git_hooks_test.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/glob.git/description b/tests/gitea-repositories-meta/user2/glob.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/glob.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/glob.git/info/exclude b/tests/gitea-repositories-meta/user2/glob.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/glob.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/readme-test.git/info/exclude b/tests/gitea-repositories-meta/user2/readme-test.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/readme-test.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo-release.git/description b/tests/gitea-repositories-meta/user2/repo-release.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo-release.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo-release.git/info/exclude b/tests/gitea-repositories-meta/user2/repo-release.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo-release.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo1.git/description b/tests/gitea-repositories-meta/user2/repo1.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo1.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo1.git/info/exclude b/tests/gitea-repositories-meta/user2/repo1.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo1.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/description b/tests/gitea-repositories-meta/user2/repo1.wiki.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo1.wiki.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/info/exclude b/tests/gitea-repositories-meta/user2/repo1.wiki.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo1.wiki.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo15.git/description b/tests/gitea-repositories-meta/user2/repo15.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo15.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo15.git/info/exclude b/tests/gitea-repositories-meta/user2/repo15.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo15.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo16.git/description b/tests/gitea-repositories-meta/user2/repo16.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo16.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo16.git/info/exclude b/tests/gitea-repositories-meta/user2/repo16.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo16.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo2.git/description b/tests/gitea-repositories-meta/user2/repo2.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo2.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo2.git/info/exclude b/tests/gitea-repositories-meta/user2/repo2.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo2.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/repo20.git/description b/tests/gitea-repositories-meta/user2/repo20.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/repo20.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo20.git/info/exclude b/tests/gitea-repositories-meta/user2/repo20.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/repo20.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/test_commit_revert.git/description b/tests/gitea-repositories-meta/user2/test_commit_revert.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/test_commit_revert.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/test_commit_revert.git/info/exclude b/tests/gitea-repositories-meta/user2/test_commit_revert.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/test_commit_revert.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user2/utf8.git/description b/tests/gitea-repositories-meta/user2/utf8.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user2/utf8.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/utf8.git/info/exclude b/tests/gitea-repositories-meta/user2/utf8.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user2/utf8.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user27/repo49.git/description b/tests/gitea-repositories-meta/user27/repo49.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user27/repo49.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user27/repo49.git/info/exclude b/tests/gitea-repositories-meta/user27/repo49.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user27/repo49.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user27/template1.git/description b/tests/gitea-repositories-meta/user27/template1.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user27/template1.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user27/template1.git/info/exclude b/tests/gitea-repositories-meta/user27/template1.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user27/template1.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user30/empty.git/objects/.keep b/tests/gitea-repositories-meta/user30/empty.git/objects/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/user30/empty.git/refs/.keep b/tests/gitea-repositories-meta/user30/empty.git/refs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/user30/renderer.git/info/exclude b/tests/gitea-repositories-meta/user30/renderer.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user30/renderer.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user30/renderer.git/refs/.keep b/tests/gitea-repositories-meta/user30/renderer.git/refs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/user40/repo60.git/description b/tests/gitea-repositories-meta/user40/repo60.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user40/repo60.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user40/repo60.git/info/exclude b/tests/gitea-repositories-meta/user40/repo60.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user40/repo60.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/gitea-repositories-meta/user40/repo60.git/objects/.keep b/tests/gitea-repositories-meta/user40/repo60.git/objects/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/user40/repo60.git/refs/.keep b/tests/gitea-repositories-meta/user40/repo60.git/refs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/user5/repo4.git/description b/tests/gitea-repositories-meta/user5/repo4.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/gitea-repositories-meta/user5/repo4.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user5/repo4.git/info/exclude b/tests/gitea-repositories-meta/user5/repo4.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/gitea-repositories-meta/user5/repo4.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index f72ac5f51c..a9db713f17 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -400,8 +400,9 @@ func MakeRequest(t testing.TB, rw *RequestWrapper, expectedStatus int) *httptest } testWebRoutes.ServeHTTP(recorder, req) if expectedStatus != NoExpectedStatus { - if !assert.EqualValues(t, expectedStatus, recorder.Code, "Request: %s %s", req.Method, req.URL.String()) { + if expectedStatus != recorder.Code { logUnexpectedResponse(t, recorder) + require.Equal(t, expectedStatus, recorder.Code, "Request: %s %s", req.Method, req.URL.String()) } } return recorder diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go index 40fcf95705..9b61bdfe87 100644 --- a/tests/integration/migration-test/migration_test.go +++ b/tests/integration/migration-test/migration_test.go @@ -64,28 +64,7 @@ func initMigrationTest(t *testing.T) func() { unittest.InitSettings() assert.True(t, len(setting.RepoRootPath) != 0) - assert.NoError(t, util.RemoveAll(setting.RepoRootPath)) - assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) - ownerDirs, err := os.ReadDir(setting.RepoRootPath) - if err != nil { - assert.NoError(t, err, "unable to read the new repo root: %v\n", err) - } - for _, ownerDir := range ownerDirs { - if !ownerDir.Type().IsDir() { - continue - } - repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name())) - if err != nil { - assert.NoError(t, err, "unable to read the new repo root: %v\n", err) - } - for _, repoDir := range repoDirs { - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755) - } - } - + assert.NoError(t, unittest.SyncDirs(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) assert.NoError(t, git.InitFull(context.Background())) setting.LoadDBSetting() setting.InitLoggersForTest() diff --git a/tests/test_utils.go b/tests/test_utils.go index 3503ca1975..8df739689d 100644 --- a/tests/test_utils.go +++ b/tests/test_utils.go @@ -195,30 +195,7 @@ func PrepareGitRepoDirectory(t testing.TB) { if !assert.NotEmpty(t, setting.RepoRootPath) { return } - - assert.NoError(t, util.RemoveAll(setting.RepoRootPath)) - assert.NoError(t, unittest.CopyDir(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) - - ownerDirs, err := os.ReadDir(setting.RepoRootPath) - if err != nil { - assert.NoError(t, err, "unable to read the new repo root: %v\n", err) - } - for _, ownerDir := range ownerDirs { - if !ownerDir.Type().IsDir() { - continue - } - repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name())) - if err != nil { - assert.NoError(t, err, "unable to read the new repo root: %v\n", err) - } - for _, repoDir := range repoDirs { - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755) - _ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "pull"), 0o755) - } - } + assert.NoError(t, unittest.SyncDirs(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) } func PrepareArtifactsStorage(t testing.TB) { -- 2.39.5