PR: https://github.com/go-gitea/gitea/pull/18752
When a test runs and the function under tests writes messages in the logs, there is no reliable way to inspect them. By adding the buffer logger at the beginning of a test and removing it at the end, all log messages written during the test are collected. It is then possible to obtain the buffer and inspect it to verify it contains the expected strings.
Although it is not a good practice to rely on log strings to assert the desired side effect of a function being tested, there are a number of functions in the Gitea code that have that behavior. In order for them to be refactored and improved to be more explicit in how they expose their side effects, the first step is to write a test for their current behavior without modifying the code. The second step is to refactor the function and run the same tests to ensure the behavior of the function was not unexpectedly modified during the refactor.
An example of such function is the extraction of the git SHA / Refs during migration.