-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logs: add the buffer logger to inspect logs during testing #18743
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
singuliere
force-pushed
the
forgefriends-mr43
branch
3 times, most recently
from
February 12, 2022 17:04
9d5b37c
to
e05b1e3
Compare
Closed
I proposed a new PR, the test code can be more simple: func TestLogChecker(t *testing.T) {
_ = log.NewLogger(1000, "console", "console", `{"level":"info","stacktracelevel":"NONE","stderr":true}`)
lc, cleanup := NewLogChecker(log.DEFAULT)
defer cleanup()
lc.ExpectContains("First", "Third")
log.Info("test")
assert.Error(t, lc.Check())
log.Info("First")
assert.Error(t, lc.Check())
log.Info("Second")
assert.Error(t, lc.Check())
log.Info("Third")
assert.NoError(t, lc.Check())
} |
GiteaBot
added
the
lgtm/need 2
This PR needs two approvals by maintainers to be considered for merging.
label
Feb 12, 2022
Because of the matter explained in this forum post, this PR is withdrawn. |
singuliere
force-pushed
the
forgefriends-mr43
branch
3 times, most recently
from
February 12, 2022 20:44
70c6c92
to
51ddc1f
Compare
Resumed as explained in this forum post. |
Comments have an id (see Gitea[0], GitLab[1], GitHub[2], etc.), and the comment migration format must represent it during migrations so that it can be used during mirroring or incremental migrations. [0] https://try.gitea.io/api/swagger#/issue/issueGetComment [1] https://docs.gitlab.com/ee/api/discussions.html#get-single-issue-discussion-item [2] https://docs.github.com/en/rest/reference/issues#get-an-issue-comment Signed-off-by: Loïc Dachary <loic@dachary.org>
singuliere
force-pushed
the
forgefriends-mr43
branch
from
February 24, 2022 23:45
c48d56d
to
4fb8cd9
Compare
Obsoleted by #18752 closing. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
forgefriends source