refactor(tests): drop the need to compile gitea binary manually (#12855)

Thanks to forgejo/forgejo!10397 (by @voidcontext), the binary called on git hooks can now be dynamically set.

**This means that we can now run tests without needing to run `make gitea` first**! No more `Could not find gitea binary` or head-banging, when one forgets to re-compile it 🎉

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12855
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
oliverpool 2026-06-02 00:04:50 +02:00 committed by Gusted
commit d11bd64691
14 changed files with 95 additions and 103 deletions

View file

@ -124,12 +124,7 @@ func MainTest(m *testing.M) {
fmt.Println("Environment variable $GITEA_ROOT not set")
os.Exit(1)
}
giteaBinary := "gitea"
setting.AppPath = path.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)
}
setting.AppPath = path.Join(giteaRoot, "gitea_migrations-should-not-need-a-binary") // use WrapMainAppPath if a binary is needed
giteaConf := os.Getenv("GITEA_CONF")
if giteaConf == "" {

View file

@ -55,7 +55,6 @@ func InitCustomSettings(confFileName string) {
if root == "" {
fatalTestError("Environment variable $GITEA_ROOT not set")
}
setting.AppPath = filepath.Join(root, "gitea")
if setting.CustomConf == "" {
templateFile := confFileName + ".tmpl"
content, err := os.ReadFile(filepath.Join(root, "tests", templateFile))
@ -100,6 +99,15 @@ type TestOptions struct {
// MainTest a reusable TestMain(..) function for unit tests that need to use a
// test database. Creates the test database, and sets necessary settings.
func MainTest(m *testing.M, testOpts ...*TestOptions) {
if _, ok := os.LookupEnv("GIT_DIR"); ok {
// The wiki tests require perform git operations.
// It worked before dropping the need for the gitea binary because in case of wiki push,
// the git hooks do not perform http requests (access permission is checked before git invocation).
log.Println("Fake git hook which accepts everything (GIT_DIR is set).")
log.Println("Forgejo with proper http hooks is available in integration tests.")
os.Exit(0)
}
searchDir, _ := os.Getwd()
for searchDir != "" {
if _, err := os.Stat(filepath.Join(searchDir, "go.mod")); err == nil {