From b266c64d241db89b77c3e09a8dbecd734f57b218 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 9 May 2026 02:12:39 +0200 Subject: [PATCH] ci: fix LFS test pollution and exclude integration packages from gogit pass Two CI failures from sharding/splitting: 1. TestAPILFSNotStarted and TestAPILFSLocksNotStarted set setting.LFS.StartServer = false but never restore it. In the pre-sharding sequential run a later test happened to set it back to true, but with sharding TestLFSRender and TestChangeRepoFilesForUpdateWithFileRename can land in a different shard and run with LFS disabled. Use test.MockVariableValue so the change is scoped to the test that makes it. 2. find-gogit-test-pkgs.sh enumerated every package whose tests import the gogit modules, including tests/integration, tests/integration/migration-test, and models/migrations/... These need a real DB / dedicated harness and have to be tested separately; mirror GO_TEST_PACKAGES' filter to exclude them. Co-Authored-By: Claude (Opus 4.7) --- tests/integration/api_repo_lfs_locks_test.go | 7 ++++--- tests/integration/api_repo_lfs_test.go | 15 +++++---------- tools/find-gogit-test-pkgs.sh | 3 +++ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/integration/api_repo_lfs_locks_test.go b/tests/integration/api_repo_lfs_locks_test.go index 460b32a7dd..0b48bd00cc 100644 --- a/tests/integration/api_repo_lfs_locks_test.go +++ b/tests/integration/api_repo_lfs_locks_test.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -22,7 +23,7 @@ import ( func TestAPILFSLocksNotStarted(t *testing.T) { defer tests.PrepareTestEnv(t)() - setting.LFS.StartServer = false + defer test.MockVariableValue(&setting.LFS.StartServer, false)() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) @@ -38,7 +39,7 @@ func TestAPILFSLocksNotStarted(t *testing.T) { func TestAPILFSLocksNotLogin(t *testing.T) { defer tests.PrepareTestEnv(t)() - setting.LFS.StartServer = true + defer test.MockVariableValue(&setting.LFS.StartServer, true)() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) @@ -51,7 +52,7 @@ func TestAPILFSLocksNotLogin(t *testing.T) { func TestAPILFSLocksLogged(t *testing.T) { defer tests.PrepareTestEnv(t)() - setting.LFS.StartServer = true + defer test.MockVariableValue(&setting.LFS.StartServer, true)() user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) // in org 3 user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) // in org 3 diff --git a/tests/integration/api_repo_lfs_test.go b/tests/integration/api_repo_lfs_test.go index 47bf244ee6..0f13bb23a8 100644 --- a/tests/integration/api_repo_lfs_test.go +++ b/tests/integration/api_repo_lfs_test.go @@ -28,8 +28,7 @@ import ( func TestAPILFSNotStarted(t *testing.T) { defer tests.PrepareTestEnv(t)() - - setting.LFS.StartServer = false + defer test.MockVariableValue(&setting.LFS.StartServer, false)() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) @@ -48,8 +47,7 @@ func TestAPILFSNotStarted(t *testing.T) { func TestAPILFSMediaType(t *testing.T) { defer tests.PrepareTestEnv(t)() - - setting.LFS.StartServer = true + defer test.MockVariableValue(&setting.LFS.StartServer, true)() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) @@ -72,8 +70,7 @@ func createLFSTestRepository(t *testing.T, repoName string) *repo_model.Reposito func TestAPILFSBatch(t *testing.T) { defer tests.PrepareTestEnv(t)() - - setting.LFS.StartServer = true + defer test.MockVariableValue(&setting.LFS.StartServer, true)() repo := createLFSTestRepository(t, "lfs-batch-repo") @@ -326,8 +323,7 @@ func TestAPILFSBatch(t *testing.T) { func TestAPILFSUpload(t *testing.T) { defer tests.PrepareTestEnv(t)() - - setting.LFS.StartServer = true + defer test.MockVariableValue(&setting.LFS.StartServer, true)() repo := createLFSTestRepository(t, "lfs-upload-repo") oid := storeObjectInRepo(t, repo.ID, "dummy3") @@ -428,8 +424,7 @@ func TestAPILFSUpload(t *testing.T) { func TestAPILFSVerify(t *testing.T) { defer tests.PrepareTestEnv(t)() - - setting.LFS.StartServer = true + defer test.MockVariableValue(&setting.LFS.StartServer, true)() repo := createLFSTestRepository(t, "lfs-verify-repo") oid := storeObjectInRepo(t, repo.ID, "dummy3") diff --git a/tools/find-gogit-test-pkgs.sh b/tools/find-gogit-test-pkgs.sh index 59525644ad..9011f07e66 100755 --- a/tools/find-gogit-test-pkgs.sh +++ b/tools/find-gogit-test-pkgs.sh @@ -8,6 +8,9 @@ set -euo pipefail tags=${1:?usage: $0 TAGS} +# Exclusions mirror the Makefile's GO_TEST_PACKAGES filter — these packages +# need a real database / dedicated harness and are tested separately. go list -tags "$tags" -f '{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}|{{range .Imports}}{{.}};{{end}}{{range .TestImports}}{{.}};{{end}}{{range .XTestImports}}{{.}};{{end}}{{end}}' ./... \ | awk -F'|' '$2 ~ /code\.gitea\.io\/gitea\/modules\/(git|gitrepo|lfs)([\.\/;]|$)/ { print $1 }' \ + | grep -vE '^code\.gitea\.io/gitea/(models/migrations(/|$)|tests(/integration(/migration-test)?)?$)' \ | sort -u