mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 19:26:09 +01:00
Merge pull request '[TESTS] add log.Level to test.NewLogChecker' (#2233) from earl-warren/forgejo:wip-logchecker into forgejo-dependency
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2233 Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
This commit is contained in:
commit
dd0af95065
|
@ -91,7 +91,7 @@ func TestPrimaryKeys(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSlowQuery(t *testing.T) {
|
||||
lc, cleanup := test.NewLogChecker("slow-query")
|
||||
lc, cleanup := test.NewLogChecker("slow-query", log.INFO)
|
||||
lc.StopMark("[Slow SQL Query]")
|
||||
defer cleanup()
|
||||
|
||||
|
@ -125,7 +125,7 @@ func TestSlowQuery(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestErrorQuery(t *testing.T) {
|
||||
lc, cleanup := test.NewLogChecker("error-query")
|
||||
lc, cleanup := test.NewLogChecker("error-query", log.INFO)
|
||||
lc.StopMark("[Error SQL Query]")
|
||||
defer cleanup()
|
||||
|
||||
|
|
|
@ -55,13 +55,15 @@ func (lc *LogChecker) checkLogEvent(event *log.EventFormatted) {
|
|||
|
||||
var checkerIndex int64
|
||||
|
||||
func NewLogChecker(namePrefix string) (logChecker *LogChecker, cancel func()) {
|
||||
func NewLogChecker(namePrefix string, level log.Level) (logChecker *LogChecker, cancel func()) {
|
||||
logger := log.GetManager().GetLogger(namePrefix)
|
||||
newCheckerIndex := atomic.AddInt64(&checkerIndex, 1)
|
||||
writerName := namePrefix + "-" + fmt.Sprint(newCheckerIndex)
|
||||
|
||||
lc := &LogChecker{}
|
||||
lc.EventWriterBaseImpl = log.NewEventWriterBase(writerName, "test-log-checker", log.WriterMode{})
|
||||
lc.EventWriterBaseImpl = log.NewEventWriterBase(writerName, "test-log-checker", log.WriterMode{
|
||||
Level: level,
|
||||
})
|
||||
logger.AddWriters(lc)
|
||||
return lc, func() { _ = logger.RemoveWriter(writerName) }
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLogChecker(t *testing.T) {
|
||||
lc, cleanup := NewLogChecker(log.DEFAULT)
|
||||
func TestLogCheckerInfo(t *testing.T) {
|
||||
lc, cleanup := NewLogChecker(log.DEFAULT, log.INFO)
|
||||
defer cleanup()
|
||||
|
||||
lc.Filter("First", "Third").StopMark("End")
|
||||
|
@ -24,11 +24,13 @@ func TestLogChecker(t *testing.T) {
|
|||
assert.False(t, stopped)
|
||||
|
||||
log.Info("First")
|
||||
log.Debug("Third")
|
||||
filtered, stopped = lc.Check(100 * time.Millisecond)
|
||||
assert.ElementsMatch(t, []bool{true, false}, filtered)
|
||||
assert.False(t, stopped)
|
||||
|
||||
log.Info("Second")
|
||||
log.Debug("Third")
|
||||
filtered, stopped = lc.Check(100 * time.Millisecond)
|
||||
assert.ElementsMatch(t, []bool{true, false}, filtered)
|
||||
assert.False(t, stopped)
|
||||
|
@ -43,3 +45,14 @@ func TestLogChecker(t *testing.T) {
|
|||
assert.ElementsMatch(t, []bool{true, true}, filtered)
|
||||
assert.True(t, stopped)
|
||||
}
|
||||
|
||||
func TestLogCheckerDebug(t *testing.T) {
|
||||
lc, cleanup := NewLogChecker(log.DEFAULT, log.DEBUG)
|
||||
defer cleanup()
|
||||
|
||||
lc.StopMark("End")
|
||||
|
||||
log.Debug("End")
|
||||
_, stopped := lc.Check(100 * time.Millisecond)
|
||||
assert.True(t, stopped)
|
||||
}
|
||||
|
|
|
@ -495,7 +495,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
|
|||
t.Run(testCase.name, func(t *testing.T) {
|
||||
stopMark := fmt.Sprintf(">>>>>>>>>>>>>STOP: %s<<<<<<<<<<<<<<<", testCase.name)
|
||||
|
||||
logChecker, cleanup := test.NewLogChecker(log.DEFAULT)
|
||||
logChecker, cleanup := test.NewLogChecker(log.DEFAULT, log.INFO)
|
||||
logChecker.Filter(testCase.logFilter...).StopMark(stopMark)
|
||||
defer cleanup()
|
||||
|
||||
|
|
Loading…
Reference in a new issue