mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-11 15:58:30 +00:00
chore: enable forcetypeassert linter, fix issues (#38804)
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert) linter to prevent unchecked type assertions. ~650 issues fixed, most fixes were clean, some use `setting.PanicInDevOrTesting`. The only behaviour changes are where code would previously send a 500 error or panic, a 4xx error is now emitted. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@ var _ EventWriter = (*eventWriterConn)(nil)
|
||||
|
||||
func NewEventWriterConn(writerName string, writerMode WriterMode) EventWriter {
|
||||
w := &eventWriterConn{EventWriterBaseImpl: NewEventWriterBase(writerName, "conn", writerMode)}
|
||||
opt := writerMode.WriterOption.(WriterConnOption)
|
||||
opt := writerMode.WriterOption.(WriterConnOption) //nolint:forcetypeassert // a conn writer is only created with WriterConnOption
|
||||
w.connWriter = connWriter{
|
||||
ReconnectOnMsg: opt.ReconnectOnMsg,
|
||||
Reconnect: opt.Reconnect,
|
||||
|
||||
@@ -21,7 +21,7 @@ var _ EventWriter = (*eventWriterConsole)(nil)
|
||||
|
||||
func NewEventWriterConsole(name string, mode WriterMode) EventWriter {
|
||||
w := &eventWriterConsole{EventWriterBaseImpl: NewEventWriterBase(name, "console", mode)}
|
||||
opt := mode.WriterOption.(WriterConsoleOption)
|
||||
opt := mode.WriterOption.(WriterConsoleOption) //nolint:forcetypeassert // a console writer is only created with WriterConsoleOption
|
||||
if opt.Stderr {
|
||||
w.OutputWriteCloser = util.NopCloser{Writer: os.Stderr}
|
||||
} else {
|
||||
|
||||
@@ -29,7 +29,7 @@ var _ EventWriter = (*eventWriterFile)(nil)
|
||||
|
||||
func NewEventWriterFile(name string, mode WriterMode) EventWriter {
|
||||
w := &eventWriterFile{EventWriterBaseImpl: NewEventWriterBase(name, "file", mode)}
|
||||
opt := mode.WriterOption.(WriterFileOption)
|
||||
opt := mode.WriterOption.(WriterFileOption) //nolint:forcetypeassert // a file writer is only created with WriterFileOption
|
||||
var err error
|
||||
w.fileWriter, err = rotatingfilewriter.Open(opt.FileName, &rotatingfilewriter.Options{
|
||||
Rotate: opt.LogRotate,
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSharedWorker(t *testing.T) {
|
||||
@@ -37,6 +38,8 @@ func TestSharedWorker(t *testing.T) {
|
||||
|
||||
m.Close()
|
||||
|
||||
logs := w.(*dummyWriter).FetchLogs()
|
||||
dw, ok := w.(*dummyWriter)
|
||||
require.True(t, ok)
|
||||
logs := dw.FetchLogs()
|
||||
assert.Equal(t, []string{"msg-1\n", "msg-2\n", "msg-3\n"}, logs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user