diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-06-07 07:27:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 07:27:09 +0200 |
commit | 3607f79d7869046d919fed05a21b55b6e61df1fa (patch) | |
tree | 9a176a4d5b67ac3a81ae210e9164d81959221ce0 /modules/log | |
parent | 51775f65bc933843199320b040186703a2bb9f51 (diff) | |
download | gitea-3607f79d7869046d919fed05a21b55b6e61df1fa.tar.gz gitea-3607f79d7869046d919fed05a21b55b6e61df1fa.zip |
Fixed assert statements. (#16089)
Diffstat (limited to 'modules/log')
-rw-r--r-- | modules/log/console_test.go | 14 | ||||
-rw-r--r-- | modules/log/file_test.go | 4 | ||||
-rw-r--r-- | modules/log/log_test.go | 50 | ||||
-rw-r--r-- | modules/log/smtp_test.go | 2 | ||||
-rw-r--r-- | modules/log/writer_test.go | 39 |
5 files changed, 54 insertions, 55 deletions
diff --git a/modules/log/console_test.go b/modules/log/console_test.go index e7ed07123b..4da87b48a3 100644 --- a/modules/log/console_test.go +++ b/modules/log/console_test.go @@ -48,7 +48,7 @@ func TestConsoleLoggerMinimalConfig(t *testing.T) { assert.Equal(t, prefix, realCW.Prefix) assert.Equal(t, "", string(written)) cw.Close() - assert.Equal(t, false, closed) + assert.False(t, closed) } } @@ -97,20 +97,20 @@ func TestConsoleLogger(t *testing.T) { expected := fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = DEBUG expected = "" cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = TRACE expected = "" cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) nonMatchEvent := Event{ level: INFO, @@ -124,15 +124,15 @@ func TestConsoleLogger(t *testing.T) { expected = "" cw.LogEvent(&nonMatchEvent) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = WARN expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] cw.Close() - assert.Equal(t, false, closed) + assert.False(t, closed) } diff --git a/modules/log/file_test.go b/modules/log/file_test.go index af6fbcb29d..7bc5f90037 100644 --- a/modules/log/file_test.go +++ b/modules/log/file_test.go @@ -30,7 +30,7 @@ func TestFileLoggerFails(t *testing.T) { fileLogger := NewFileLogger() //realFileLogger, ok := fileLogger.(*FileLogger) - //assert.Equal(t, true, ok) + //assert.True(t, ok) // Fail if there is bad json err = fileLogger.Init("{") @@ -161,7 +161,7 @@ func TestCompressFileLogger(t *testing.T) { fileLogger := NewFileLogger() realFileLogger, ok := fileLogger.(*FileLogger) - assert.Equal(t, true, ok) + assert.True(t, ok) location, _ := time.LoadLocation("EST") diff --git a/modules/log/log_test.go b/modules/log/log_test.go index 810505dea5..d14daa5a20 100644 --- a/modules/log/log_test.go +++ b/modules/log/log_test.go @@ -26,9 +26,9 @@ func baseConsoleTest(t *testing.T, logger *MultiChannelledLogger) (chan []byte, channelledLog := m.GetEventLogger("console") assert.NotEmpty(t, channelledLog) realChanLog, ok := channelledLog.(*ChannelledLog) - assert.Equal(t, true, ok) + assert.True(t, ok) realCL, ok := realChanLog.loggerProvider.(*ConsoleLogger) - assert.Equal(t, true, ok) + assert.True(t, ok) assert.Equal(t, INFO, realCL.Level) realCL.out = c @@ -38,20 +38,20 @@ func baseConsoleTest(t *testing.T, logger *MultiChannelledLogger) (chan []byte, logger.Log(0, INFO, format, args...) line := <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) format = "test2: %s" logger.Warn(format, args...) line = <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) format = "testerror: %s" logger.Error(format, args...) line = <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) return written, closed } @@ -63,7 +63,7 @@ func TestNewLoggerUnexported(t *testing.T) { out := logger.MultiChannelledLog.GetEventLogger("console") assert.NotEmpty(t, out) chanlog, ok := out.(*ChannelledLog) - assert.Equal(t, true, ok) + assert.True(t, ok) assert.Equal(t, "console", chanlog.provider) assert.Equal(t, INFO, logger.GetLevel()) baseConsoleTest(t, logger) @@ -74,11 +74,11 @@ func TestNewLoggger(t *testing.T) { logger := NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) assert.Equal(t, INFO, GetLevel()) - assert.Equal(t, false, IsTrace()) - assert.Equal(t, false, IsDebug()) - assert.Equal(t, true, IsInfo()) - assert.Equal(t, true, IsWarn()) - assert.Equal(t, true, IsError()) + assert.False(t, IsTrace()) + assert.False(t, IsDebug()) + assert.True(t, IsInfo()) + assert.True(t, IsWarn()) + assert.True(t, IsError()) written, closed := baseConsoleTest(t, logger) @@ -88,17 +88,17 @@ func TestNewLoggger(t *testing.T) { Log(0, INFO, format, args...) line := <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) Info(format, args...) line = <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) go DelLogger("console") line = <-written assert.Equal(t, "", string(line)) - assert.Equal(t, true, <-closed) + assert.True(t, <-closed) } func TestNewLogggerRecreate(t *testing.T) { @@ -106,11 +106,11 @@ func TestNewLogggerRecreate(t *testing.T) { NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) assert.Equal(t, INFO, GetLevel()) - assert.Equal(t, false, IsTrace()) - assert.Equal(t, false, IsDebug()) - assert.Equal(t, true, IsInfo()) - assert.Equal(t, true, IsWarn()) - assert.Equal(t, true, IsError()) + assert.False(t, IsTrace()) + assert.False(t, IsDebug()) + assert.True(t, IsInfo()) + assert.True(t, IsWarn()) + assert.True(t, IsError()) format := "test: %s" args := []interface{}{"A"} @@ -120,11 +120,11 @@ func TestNewLogggerRecreate(t *testing.T) { NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) assert.Equal(t, INFO, GetLevel()) - assert.Equal(t, false, IsTrace()) - assert.Equal(t, false, IsDebug()) - assert.Equal(t, true, IsInfo()) - assert.Equal(t, true, IsWarn()) - assert.Equal(t, true, IsError()) + assert.False(t, IsTrace()) + assert.False(t, IsDebug()) + assert.True(t, IsInfo()) + assert.True(t, IsWarn()) + assert.True(t, IsError()) Log(0, INFO, format, args...) @@ -150,5 +150,5 @@ func TestNewNamedLogger(t *testing.T) { go DelNamedLogger("test") line := <-written assert.Equal(t, "", string(line)) - assert.Equal(t, true, <-closed) + assert.True(t, <-closed) } diff --git a/modules/log/smtp_test.go b/modules/log/smtp_test.go index 216d555215..c8758bf6be 100644 --- a/modules/log/smtp_test.go +++ b/modules/log/smtp_test.go @@ -26,7 +26,7 @@ func TestSMTPLogger(t *testing.T) { logger := NewSMTPLogger() smtpLogger, ok := logger.(*SMTPLogger) - assert.Equal(t, true, ok) + assert.True(t, ok) err := logger.Init(fmt.Sprintf("{\"prefix\":\"%s\",\"level\":\"%s\",\"flags\":%d,\"username\":\"%s\",\"password\":\"%s\",\"host\":\"%s\",\"subject\":\"%s\",\"sendTos\":[\"%s\",\"%s\"]}", prefix, level.String(), flags, username, password, host, subject, sendTos[0], sendTos[1])) assert.NoError(t, err) diff --git a/modules/log/writer_test.go b/modules/log/writer_test.go index 886dd58fb3..99a5fd3406 100644 --- a/modules/log/writer_test.go +++ b/modules/log/writer_test.go @@ -64,44 +64,44 @@ func TestBaseLogger(t *testing.T) { expected := fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = DEBUG expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = TRACE expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = WARN expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = ERROR expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = CRITICAL expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] b.Close() - assert.Equal(t, true, closed) + assert.True(t, closed) } func TestBaseLoggerDated(t *testing.T) { @@ -142,46 +142,46 @@ func TestBaseLoggerDated(t *testing.T) { expected := fmt.Sprintf("%s%s %s:%d [%s] %s", prefix, dateString, "FILENAME", event.line, strings.ToUpper(event.level.String()), event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = INFO expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = ERROR expected = fmt.Sprintf("%s%s %s:%d [%s] %s", prefix, dateString, "FILENAME", event.line, strings.ToUpper(event.level.String()), event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = DEBUG expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = CRITICAL expected = fmt.Sprintf("%s%s %s:%d [%s] %s", prefix, dateString, "FILENAME", event.line, strings.ToUpper(event.level.String()), event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = TRACE expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] b.Close() - assert.Equal(t, true, closed) + assert.True(t, closed) } func TestBaseLoggerMultiLineNoFlagsRegexp(t *testing.T) { @@ -222,20 +222,20 @@ func TestBaseLoggerMultiLineNoFlagsRegexp(t *testing.T) { expected := "TEST\n\tMESSAGE\n\tTEST\n" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.filename = "ELSEWHERE" b.LogEvent(&event) assert.Equal(t, "", string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.caller = "FILENAME" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event = Event{ @@ -249,9 +249,8 @@ func TestBaseLoggerMultiLineNoFlagsRegexp(t *testing.T) { expected = "TEST\n\tFILENAME\n\tTEST\n" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] - } func TestBrokenRegexp(t *testing.T) { @@ -273,5 +272,5 @@ func TestBrokenRegexp(t *testing.T) { b.NewWriterLogger(c) assert.Empty(t, b.regexp) b.Close() - assert.Equal(t, true, closed) + assert.True(t, closed) } |