Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
version: "2"
run:
tests: false
linters:
enable:
- asasalint
Expand All @@ -23,8 +21,16 @@ linters:
- noctx
- reassign
- recvcheck
- testifylint
- unparam
exclusions:
presets:
- legacy
- std-error-handling
rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gosec
- musttag
- noctx # TODO: enable once we switch to Go 1.24+.
1 change: 1 addition & 0 deletions alt_exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestHandler(t *testing.T) {

outfile := filepath.Join(tempDir, "outfile.out")
arg := time.Now().UTC().String()
// TODO: change to exec.CommandContext(t.Context(), ...) once we switch to Go 1.24+.
err = exec.Command("go", "run", gofile, outfile, arg).Run()
if err == nil {
t.Fatalf("completed normally, should have failed")
Expand Down
19 changes: 10 additions & 9 deletions hooks/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ func TestAllHooks(t *testing.T) {

logger, hook := NewNullLogger()
assert.Nil(hook.LastEntry())
assert.Equal(0, len(hook.Entries))
assert.Empty(hook.Entries)

logger.Error("Hello error")
assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal("Hello error", hook.LastEntry().Message)
assert.Equal(1, len(hook.Entries))
assert.Len(hook.Entries, 1)

logger.Warn("Hello warning")
assert.Equal(logrus.WarnLevel, hook.LastEntry().Level)
assert.Equal("Hello warning", hook.LastEntry().Message)
assert.Equal(2, len(hook.Entries))
assert.Len(hook.Entries, 2)

hook.Reset()
assert.Nil(hook.LastEntry())
assert.Equal(0, len(hook.Entries))
assert.Empty(hook.Entries)

hook = NewGlobal()

logrus.Error("Hello error")
assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal("Hello error", hook.LastEntry().Message)
assert.Equal(1, len(hook.Entries))
assert.Len(hook.Entries, 1)
}

func TestLoggingWithHooksRace(t *testing.T) {
Expand Down Expand Up @@ -69,9 +69,10 @@ func TestLoggingWithHooksRace(t *testing.T) {
wgAll.Wait()

entries := hook.AllEntries()
assert.Equal(100, len(entries))
assert.Len(entries, 100)
}

// nolint:staticcheck // linter assumes logger.Fatal exits, resulting in false SA4006 warnings.
func TestFatalWithAlternateExit(t *testing.T) {
assert := assert.New(t)

Expand All @@ -81,7 +82,7 @@ func TestFatalWithAlternateExit(t *testing.T) {
logger.Fatal("something went very wrong")
assert.Equal(logrus.FatalLevel, hook.LastEntry().Level)
assert.Equal("something went very wrong", hook.LastEntry().Message)
assert.Equal(1, len(hook.Entries))
assert.Len(hook.Entries, 1)
}

func TestNewLocal(t *testing.T) {
Expand All @@ -93,10 +94,10 @@ func TestNewLocal(t *testing.T) {

wg.Add(10)
for i := 0; i < 10; i++ {
go func(i int) {
go func() {
logger.Info("info")
wg.Done()
}(i)
}()
}

hook := NewLocal(logger)
Expand Down
4 changes: 2 additions & 2 deletions json_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func TestJSONMessageKey(t *testing.T) {
t.Fatal("Unable to format entry: ", err)
}
s := string(b)
if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) {
if !strings.Contains(s, `"message":"oh hai"`) {
t.Fatal("Expected JSON to format message key")
}
}
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestJSONEnableHTMLEscape(t *testing.T) {
t.Fatal("Unable to format entry: ", err)
}
s := string(b)
if !(strings.Contains(s, "u0026") && strings.Contains(s, "u003e") && strings.Contains(s, "u003c")) {
if !strings.Contains(s, `\u0026 \u003c \u003e`) {
t.Error("Message should be HTML escaped", s)
}
}
10 changes: 5 additions & 5 deletions logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestUserSuppliedLevelFieldHasPrefix(t *testing.T) {
log.WithField("level", 1).Info("test")
}, func(fields Fields) {
assert.Equal(t, "info", fields["level"])
assert.Equal(t, 1.0, fields["fields.level"]) // JSON has floats only
assert.InDelta(t, 1.0, fields["fields.level"], 0.0001) // JSON has floats only
})
}

Expand Down Expand Up @@ -342,7 +342,7 @@ func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {

err := json.Unmarshal(buffer.Bytes(), &fields)
require.NoError(t, err, "should have decoded first message")
assert.Equal(t, 4, len(fields), "should only have msg/time/level/context fields")
assert.Len(t, fields, 4, "should only have msg/time/level/context fields")
assert.Equal(t, "looks delicious", fields["msg"])
assert.Equal(t, "eating raw fish", fields["context"])

Expand All @@ -352,7 +352,7 @@ func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {

err = json.Unmarshal(buffer.Bytes(), &fields)
require.NoError(t, err, "should have decoded second message")
assert.Equal(t, 4, len(fields), "should only have msg/time/level/context fields")
assert.Len(t, fields, 4, "should only have msg/time/level/context fields")
assert.Equal(t, "omg it is!", fields["msg"])
assert.Equal(t, "eating raw fish", fields["context"])
assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
Expand All @@ -375,7 +375,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {

err := json.Unmarshal(buffer.Bytes(), &fields)
require.NoError(t, err, "should have decoded first message")
assert.Equal(t, 6, len(fields), "should have msg/time/level/func/context fields")
assert.Len(t, fields, 6, "should have msg/time/level/func/context fields")
assert.Equal(t, "looks delicious", fields["msg"])
assert.Equal(t, "eating raw fish", fields["context"])
assert.Equal(t,
Expand All @@ -401,7 +401,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {

err = json.Unmarshal(buffer.Bytes(), &fields)
require.NoError(t, err, "should have decoded second message")
assert.Equal(t, 11, len(fields), "should have all builtin fields plus foo,bar,baz,...")
assert.Len(t, fields, 11, "should have all builtin fields plus foo,bar,baz,...")
assert.Equal(t, "Stubblefield", fields["Clyde"])
assert.Equal(t, "Starks", fields["Jab'o"])
assert.Equal(t, "https://www.youtube.com/watch?v=V5DTznu-9v0", fields["uri"])
Expand Down
2 changes: 1 addition & 1 deletion text_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func TestTextFormatterIsColored(t *testing.T) {
}
res := tf.isColored()
if runtime.GOOS == "windows" && !tf.ForceColors && !val.clicolorForceIsSet {
assert.Equal(subT, false, res)
assert.False(subT, res)
} else {
assert.Equal(subT, val.expectedResult, res)
}
Expand Down
Loading