-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
migrations: add test for importing pull requests in gitea uploader #18752
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dba322f
logs: add the buffer logger to inspect logs during testing
72cd64e
migrations: add test for importing pull requests in gitea uploader
a8c5b17
for each git.OpenRepositoryCtx, call Close
dcf21dc
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere 22756fe
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere 67d157d
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere 15f64a1
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere 05ad70a
Content is expected to return the content of the log
ee7c13a
test for errors before defer
cdc21ce
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere 786cacb
Merge branch 'main' into forgefriends-mr44
zeripath 8c965b6
Merge branch 'main' into forgefriends-mr44
lunny 508e0ac
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere d0329e9
Merge remote-tracking branch 'origin/main' into forgefriends-mr44
singuliere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package log | ||
|
||
import ( | ||
"bytes" | ||
"sync" | ||
) | ||
|
||
type bufferWriteCloser struct { | ||
mu sync.Mutex | ||
buffer bytes.Buffer | ||
} | ||
|
||
func (b *bufferWriteCloser) Write(p []byte) (int, error) { | ||
b.mu.Lock() | ||
defer b.mu.Unlock() | ||
return b.buffer.Write(p) | ||
} | ||
|
||
func (b *bufferWriteCloser) Close() error { | ||
return nil | ||
} | ||
|
||
func (b *bufferWriteCloser) String() string { | ||
b.mu.Lock() | ||
defer b.mu.Unlock() | ||
return b.buffer.String() | ||
} | ||
|
||
// BufferLogger implements LoggerProvider and writes messages in a buffer. | ||
type BufferLogger struct { | ||
WriterLogger | ||
} | ||
|
||
// NewBufferLogger create BufferLogger returning as LoggerProvider. | ||
func NewBufferLogger() LoggerProvider { | ||
log := &BufferLogger{} | ||
log.NewWriterLogger(&bufferWriteCloser{}) | ||
return log | ||
} | ||
|
||
// Init inits connection writer | ||
func (log *BufferLogger) Init(string) error { | ||
log.NewWriterLogger(log.out) | ||
return nil | ||
} | ||
|
||
// Content returns the content accumulated in the content provider | ||
func (log *BufferLogger) Content() (string, error) { | ||
return log.out.(*bufferWriteCloser).String(), nil | ||
} | ||
|
||
// Flush when log should be flushed | ||
func (log *BufferLogger) Flush() { | ||
} | ||
|
||
// ReleaseReopen does nothing | ||
func (log *BufferLogger) ReleaseReopen() error { | ||
return nil | ||
} | ||
|
||
// GetName returns the default name for this implementation | ||
func (log *BufferLogger) GetName() string { | ||
return "buffer" | ||
} | ||
|
||
func init() { | ||
Register("buffer", NewBufferLogger) | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBufferLogger(t *testing.T) { | ||
logger := NewBufferLogger() | ||
bufferLogger := logger.(*BufferLogger) | ||
assert.NotNil(t, bufferLogger) | ||
|
||
err := logger.Init("") | ||
assert.NoError(t, err) | ||
|
||
location, _ := time.LoadLocation("EST") | ||
date := time.Date(2019, time.January, 13, 22, 3, 30, 15, location) | ||
|
||
msg := "TEST MSG" | ||
event := Event{ | ||
level: INFO, | ||
msg: msg, | ||
caller: "CALLER", | ||
filename: "FULL/FILENAME", | ||
line: 1, | ||
time: date, | ||
} | ||
logger.LogEvent(&event) | ||
content, err := bufferLogger.Content() | ||
assert.NoError(t, err) | ||
assert.Contains(t, content, msg) | ||
logger.Close() | ||
} | ||
|
||
func TestBufferLoggerContent(t *testing.T) { | ||
level := INFO | ||
logger := NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) | ||
|
||
logger.SetLogger("buffer", "buffer", "{}") | ||
defer logger.DelLogger("buffer") | ||
|
||
msg := "A UNIQUE MESSAGE" | ||
Error(msg) | ||
|
||
found := false | ||
for i := 0; i < 30000; i++ { | ||
content, err := logger.GetLoggerProviderContent("buffer") | ||
assert.NoError(t, err) | ||
if strings.Contains(content, msg) { | ||
found = true | ||
break | ||
} | ||
time.Sleep(1 * time.Millisecond) | ||
} | ||
assert.True(t, found) | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.