Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Filter gitea-specific variables when running tests#36070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
hramrach wants to merge1 commit intogo-gitea:main
base:main
Choose a base branch
Loading
fromhramrach:main

Conversation

@hramrach
Copy link
Contributor

The test code expects that GITEA_CUSTOM is not set. While there is no reason to set this variable some misguided packagers set it globally in /etc/profile rather than in the service definition.

Fixes:#36042

@GiteaBotGiteaBot added the lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelDec 2, 2025
Makefile Outdated
test-backend:## test backend files
@echo"Running go test with$(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
@$(GO)test$(GOTESTFLAGS) -tags='$(TEST_TAGS)'$(GO_TEST_PACKAGES)
@GITEA_CUSTOM=$(GO)test$(GOTESTFLAGS) -tags='$(TEST_TAGS)'$(GO_TEST_PACKAGES)
Copy link
Contributor

@wxiaoguangwxiaoguangDec 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It won't really "fix" the problem.

Developers can also run the tests directly via IDE (see the screenshot), it is useful for step-by-step debugging via the debugger.

Detailsimage

Then you introduce more surprises for developers: whymake test succeeds, but manually running one test fails.

Instead of keeping adding more patches, you can show a warning to developers: there is a pre-defined GITEA_CUSTOM environment variable and it will affect the tests.

Actually, not onlyGITEA_CUSTOM, there are far more similar environment variables, for example:GITEA_WORK_DIR,GITEA_RUN_MODE, etc


For other reviewers: the root problem is that some downstream packages have incorrect behaviors, then the whole system is polluted with a globalGITEA_CUSTOM, for example:

https://build.opensuse.org/projects/devel:tools:scm/packages/gitea/files/gitea.profile.sh?expand=1

Since the system is polluted, the fix should be done by the downstream packages, otherwise the abused paths will cause more problems.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You already have stuff like

GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test

It does not sound like the existing test design sticks to the principle that running tests standalone without the setup done in the makefile works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It does not sound like the existing test design sticks to the principle that running tests standalone without the setup done in the makefile works.

That's just your guess.

The tests do run standalone, and it helped to get many bugs fixed (I used the debugger to fix#35946,#35899,#35858,#35797, and more)

image

Copy link
Member

@silverwindsilverwindDec 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We do need to ensure that tests run in a controlled environment. As a more general solution, I'd recommend we add a dotenv file liketest.env and make sure this file is loaded before every test, and it has to work withgo test too, e.g. no Makefile involved.

https://github.com/joho/godotenv can be used to load dotenv files.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why does the makefile pass environment variables to that test if it's supposed to run standalone then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, that's why using environment variables fro configuration is ReallyBadIdea™.

Using environment variables for configuration isn't really bad, many modern libraries also support it, and git also support it.

Polluting user's environment variables is the real bad idea.

Copy link
Contributor

@wxiaoguangwxiaoguangDec 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Downstream can use-X "setting.CustomPath=/etc/gitea" for Makefile'sLDFLAGS

Then the binary will use the correct path and config without any global variable.


If downstream only want to pack existing binary, they can use Gitea's docker's wrapper script:https://github.com/go-gitea/gitea/blob/main/docker/root/usr/local/bin/gitea

Then no global variable is needed.


These 2 are the proper fixes. The wrapper script is recommended, it doesn't need to use any special build

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You enumerate the reasons why it's bad and then say it's not really bad, and argue others are doing it.

No, itis bad to use environment variables for configuration. It is obfuscation of configuration, a way to slip some configuration behind the user's back.

If environment variables were not used in the code we would not have these discussions, there would be nothing to pollute.

And it's still very much possible to use make variables to pass in configuration even if the code under test does not use environment variables.

And when not using make it's possible to pass commandline arguments. A thing that it explicit, visible, and cannot be slipped into a file behind the user's back.

That's not to say that gitea should stop using environment variables for configuration overnight or even at all. Change is hard, and takes a long time when attempted.

Copy link
Contributor

@TheFox0x7TheFox0x7Dec 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Isn't the solution the most basic part of tests? Clean environment? Which CI, clean VM or container generally provides?

Funny thing about env vars and git being relevant - you know what tests fail on my local setup? Yup. Git. Specifically XDG_CONFIG_HOME is set so config edits default to that. Never bothered to report it or look into it as I know it's fixed in the proper binary and runningXDG_CONFIG_HOME= make test-backend isn't really a bother. I find it ironic considering this entire thread :)

No, it is bad to use environment variables for configuration. It is obfuscation of configuration, a way to slip some configuration behind the user's back.

I think you should tell that to users of kubernetes and docker/podman. And people fromhttps://12factor.net/config. And after all that deal with users of gitea/any other app explaining that it's not a regression and they have to rewrite their config to use file instead of env vars.

Copy link
Contributor

@wxiaoguangwxiaoguangDec 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe you should also convince other projects that "environment variables are bad":

  • Let Golang drop theirGOPROXY
  • Let Docker drop theirDOCKER_BUILDKIT
  • Let git drop theirGIT_COMMITTER_NAME
  • Let Zypper drop theirZYPP_CONF

OK, I have explained everything.

I will unsubscribe this thread to save everyone's time. As always: you can choose to believe or not, and do the things that you think are right.

@hramrachhramrach marked this pull request as draftDecember 2, 2025 19:55
@hramrachhramrach changed the titleMakefile: Unset GITEA_CUSTOM when running testsDraft: Makefile: Unset GITEA_CUSTOM when running testsDec 2, 2025
@github-actionsgithub-actionsbot added the modifies/goPull requests that update Go code labelDec 5, 2025
@hramrachhramrachforce-pushed themain branch 5 times, most recently fromfb0b282 toa5682e7CompareDecember 5, 2025 09:01
@hramrachhramrach marked this pull request as ready for reviewDecember 5, 2025 09:01
@hramrachhramrach changed the titleDraft: Makefile: Unset GITEA_CUSTOM when running testsFilter gitea-specific variables when running testsDec 5, 2025
@GiteaBotGiteaBot added lgtm/need 1This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelsDec 17, 2025
@lunny
Copy link
Member

GITEA_UNIT_TESTS_LOG_SQL should be kept, sometimes it's useful when run tests.

@silverwind
Copy link
Member

GITEA_UNIT_TESTS_LOG_SQL should be kept, sometimes it's useful when run tests.

Hmm, should we add theGITEA_UNIT_TESTS_ prefix to the include list?

lunny reacted with thumbs up emoji

@lunny
Copy link
Member

It's better to have a new function likeprepareForUnitTest to include all theseenv.Filter and etc. code.

@hramrach
Copy link
ContributorAuthor

It's better to have a new function likeprepareForUnitTest to include all theseenv.Filter and etc. code.

A lot of test do actually. There are a few cases of tests that call gitea functions but do not use any such existing subframework.

@hramrachhramrachforce-pushed themain branch 3 times, most recently fromab4d1bd to995ace3CompareDecember 17, 2025 21:28
@hramrach
Copy link
ContributorAuthor

In most cases calling InitTest() causes import loop. Only few tests that did not so far can make use of it.

@hramrachhramrachforce-pushed themain branch 2 times, most recently fromc83c36d tobc91e49CompareDecember 17, 2025 21:58
There is no particular reason to set gitea variables globally.Nonetheless, some misguided packagers set GITEA_CUSTOM in /etc/profilebreaking tests.Fixes:go-gitea#36042
@wxiaoguang
Copy link
Contributor

How to handle env vars:#36070 (comment)

@silverwind
Copy link
Member

How to handle env vars:#36070 (comment)

You mean it should just useClearenv?

t.Setenv("FOO","bar")
Filter([]string{}, []string{"GITEA_"})
ifos.Getenv("GITEA_FOO")!="" {
t.FailNow()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

entire codebase uses testify package, so let's stick to that.

@wxiaoguang
Copy link
Contributor

How to handle env vars:#36070 (comment)

You mean it should just useClearenv?

No, I didn't mentionClearenv, it's not my comment.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@wxiaoguangwxiaoguangwxiaoguang left review comments

@silverwindsilverwindsilverwind approved these changes

+1 more reviewer

@TheFox0x7TheFox0x7TheFox0x7 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

lgtm/need 1This PR needs approval from one additional maintainer to be merged.modifies/goPull requests that update Go codemodifies/internal

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Tests fail

6 participants

@hramrach@lunny@silverwind@wxiaoguang@TheFox0x7@GiteaBot

[8]ページ先頭

©2009-2025 Movatter.jp