mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
chore(lint): enable thelper (#6488)
thelper requires test helpers to call t.Helper() first, so failures point at the caller, and keeps the testing param first. Fixed 7 sites by hand: 4 helpers now call Helper(), 3 subtest bodies inlined into t.Run. The parameter name checks are off: renaming t to tb adds churn, not better line numbers.
This commit is contained in:
parent
3fca50b808
commit
1286fdfc9c
@ -29,6 +29,7 @@ linters:
|
||||
- nolintlint
|
||||
- rowserrcheck
|
||||
- staticcheck
|
||||
- thelper
|
||||
- unconvert
|
||||
- usetesting
|
||||
- whitespace
|
||||
@ -162,6 +163,16 @@ linters:
|
||||
staticcheck:
|
||||
dot-import-whitelist:
|
||||
- github.com/Masterminds/squirrel
|
||||
thelper:
|
||||
# Helper() is what fixes failure line numbers; the t/tb/b/f parameter name does not
|
||||
test:
|
||||
name: false
|
||||
benchmark:
|
||||
name: false
|
||||
tb:
|
||||
name: false
|
||||
fuzz:
|
||||
name: false
|
||||
exclusions:
|
||||
rules:
|
||||
- linters:
|
||||
|
||||
@ -15,8 +15,14 @@ func BenchmarkImageDecode(b *testing.B) {
|
||||
name string
|
||||
gen func(tb testing.TB, w, h int) []byte
|
||||
}{
|
||||
{"jpeg", func(tb testing.TB, w, h int) []byte { return generateJPEG(tb, w, h, 75) }},
|
||||
{"png", func(tb testing.TB, w, h int) []byte { return generatePNG(tb, w, h) }},
|
||||
{"jpeg", func(tb testing.TB, w, h int) []byte {
|
||||
tb.Helper()
|
||||
return generateJPEG(tb, w, h, 75)
|
||||
}},
|
||||
{"png", func(tb testing.TB, w, h int) []byte {
|
||||
tb.Helper()
|
||||
return generatePNG(tb, w, h)
|
||||
}},
|
||||
}
|
||||
|
||||
for _, format := range formats {
|
||||
|
||||
@ -33,13 +33,11 @@ func TestLevels(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
fn := func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h.AcceptedLevels = test.acceptedLevels
|
||||
levels := h.Levels()
|
||||
assert.Equal(t, test.expected, levels, test.description)
|
||||
}
|
||||
|
||||
t.Run(test.name, fn)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,12 +81,10 @@ func TestLevelThreshold(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
fn := func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
levels := levelThreshold(test.level)
|
||||
assert.Equal(t, test.expected, levels, test.description)
|
||||
}
|
||||
|
||||
t.Run(test.name, fn)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +132,7 @@ func TestEntryDataValues(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
fn := func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
logEntry := &logrus.Entry{
|
||||
Data: test.logFields,
|
||||
}
|
||||
@ -145,8 +141,7 @@ func TestEntryDataValues(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, test.expected, logEntry.Data)
|
||||
}
|
||||
t.Run(test.name, fn)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ func loadLyricFixture(b *testing.B, name string) []byte {
|
||||
}
|
||||
|
||||
func benchmarkParse(b *testing.B, suffix, fixture string) {
|
||||
b.Helper()
|
||||
contents := loadLyricFixture(b, fixture)
|
||||
b.ReportAllocs()
|
||||
b.SetBytes(int64(len(contents)))
|
||||
|
||||
@ -18,6 +18,7 @@ var (
|
||||
)
|
||||
|
||||
func Init(t testing.TB, skipOnShort bool) {
|
||||
t.Helper()
|
||||
if skipOnShort && testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user