Skip to content

Commit ef25537

Browse files
committed
fix revive issues
In golangci-lint and upstream, revive has replaced golint because golint is no longer maintained. revive finds some more issues that need to be fixed before it can be used: ktesting/testinglogger.go:81:20: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive) func (n NopTL) Log(args ...interface{}) {} ^ klogr/klogr_test.go:23:2: redefines-builtin-id: redefinition of the built-in function new (revive) new := func() logr.Logger { switch format { case formatNew: return New() case formatDefault: return NewWithOptions() default: return NewWithOptions(WithFormat(Format(format))) } } internal/clock/testing/fake_clock.go:261:29: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive) func (*IntervalClock) After(d time.Duration) <-chan time.Time { ^ internal/clock/testing/fake_clock.go:267:32: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive) func (*IntervalClock) NewTimer(d time.Duration) clock.Timer { ^ internal/clock/testing/fake_clock.go:273:33: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive) func (*IntervalClock) AfterFunc(d time.Duration, f func()) clock.Timer { ^ textlogger/textlogger.go:148:2: redefines-builtin-id: redefinition of the built-in function new (revive) new := *l ^ textlogger/textlogger.go:157:2: redefines-builtin-id: redefinition of the built-in function new (revive) new := *l ^ textlogger/textlogger.go:91:24: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive) func (l *tlogger) Info(level int, msg string, kvList ...interface{}) { ^ klog_test.go:2204:2: redefines-builtin-id: redefinition of the built-in function copy (revive) copy := settings.deepCopy() ^ klog_test.go:95:48: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive) func contains(s severity.Severity, str string, t *testing.T) bool { ^ klog_test.go:378:28: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive) func TestSetOutputDataRace(t *testing.T) { ^ klog_test.go:1807:25: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive) func (l *testLogr) Info(level int, msg string, keysAndValues ...interface{}) { ^ klog_test.go:1828:25: unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive) func (l *testLogr) Init(info logr.RuntimeInfo) {} ^ klog_test.go:1829:28: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive) func (l *testLogr) Enabled(level int) bool { return true } ^ klog_test.go:1833:34: unused-parameter: parameter 'depth' seems to be unused, consider removing or renaming it as _ (revive) func (l *testLogr) WithCallDepth(depth int) logr.LogSink { return l } ^
1 parent a4f9060 commit ef25537

File tree

6 files changed

+69
-67
lines changed

6 files changed

+69
-67
lines changed

examples/output_test/output_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import (
3434
"k8s.io/klog/v2/textlogger"
3535
)
3636

37-
func newLogger(out io.Writer, v int, vmodule string) logr.Logger {
37+
// newLogger is a test.OutputConfig.NewLogger callback which creates a zapr
38+
// logger. The vmodule parameter is ignored because zapr does not support that.
39+
func newLogger(out io.Writer, v int, _ string) logr.Logger {
3840
return newZaprLogger(out, v)
3941
}
4042

internal/clock/testing/fake_clock.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -258,30 +258,30 @@ func (i *IntervalClock) Since(ts time.Time) time.Duration {
258258

259259
// After is unimplemented, will panic.
260260
// TODO: make interval clock use FakeClock so this can be implemented.
261-
func (*IntervalClock) After(d time.Duration) <-chan time.Time {
261+
func (*IntervalClock) After(time.Duration) <-chan time.Time {
262262
panic("IntervalClock doesn't implement After")
263263
}
264264

265265
// NewTimer is unimplemented, will panic.
266266
// TODO: make interval clock use FakeClock so this can be implemented.
267-
func (*IntervalClock) NewTimer(d time.Duration) clock.Timer {
267+
func (*IntervalClock) NewTimer(time.Duration) clock.Timer {
268268
panic("IntervalClock doesn't implement NewTimer")
269269
}
270270

271271
// AfterFunc is unimplemented, will panic.
272272
// TODO: make interval clock use FakeClock so this can be implemented.
273-
func (*IntervalClock) AfterFunc(d time.Duration, f func()) clock.Timer {
273+
func (*IntervalClock) AfterFunc(time.Duration, func()) clock.Timer {
274274
panic("IntervalClock doesn't implement AfterFunc")
275275
}
276276

277277
// NewTicker has no implementation yet and is omitted.
278278
// TODO: make interval clock use FakeClock so this can be implemented.
279-
func (*IntervalClock) NewTicker(d time.Duration) clock.Ticker {
279+
func (*IntervalClock) NewTicker(time.Duration) clock.Ticker {
280280
panic("IntervalClock doesn't implement NewTicker")
281281
}
282282

283283
// Sleep is unimplemented, will panic.
284-
func (*IntervalClock) Sleep(d time.Duration) {
284+
func (*IntervalClock) Sleep(time.Duration) {
285285
panic("IntervalClock doesn't implement Sleep")
286286
}
287287

klog_test.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func contents(s severity.Severity) string {
9292
}
9393

9494
// contains reports whether the string is contained in the log.
95-
func contains(s severity.Severity, str string, t *testing.T) bool {
95+
func contains(s severity.Severity, str string) bool {
9696
return strings.Contains(contents(s), str)
9797
}
9898

@@ -108,10 +108,10 @@ func TestInfo(t *testing.T) {
108108
setFlags()
109109
defer logging.swap(logging.newBuffers())
110110
Info("test")
111-
if !contains(severity.InfoLog, "I", t) {
111+
if !contains(severity.InfoLog, "I") {
112112
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
113113
}
114-
if !contains(severity.InfoLog, "test", t) {
114+
if !contains(severity.InfoLog, "test") {
115115
t.Error("Info failed")
116116
}
117117
}
@@ -181,10 +181,10 @@ func TestStandardLog(t *testing.T) {
181181
setFlags()
182182
defer logging.swap(logging.newBuffers())
183183
stdLog.Print("test")
184-
if !contains(severity.InfoLog, "I", t) {
184+
if !contains(severity.InfoLog, "I") {
185185
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
186186
}
187-
if !contains(severity.InfoLog, "test", t) {
187+
if !contains(severity.InfoLog, "test") {
188188
t.Error("Info failed")
189189
}
190190
}
@@ -239,17 +239,17 @@ func TestError(t *testing.T) {
239239
setFlags()
240240
defer logging.swap(logging.newBuffers())
241241
Error("test")
242-
if !contains(severity.ErrorLog, "E", t) {
242+
if !contains(severity.ErrorLog, "E") {
243243
t.Errorf("Error has wrong character: %q", contents(severity.ErrorLog))
244244
}
245-
if !contains(severity.ErrorLog, "test", t) {
245+
if !contains(severity.ErrorLog, "test") {
246246
t.Error("Error failed")
247247
}
248248
str := contents(severity.ErrorLog)
249-
if !contains(severity.WarningLog, str, t) {
249+
if !contains(severity.WarningLog, str) {
250250
t.Error("Warning failed")
251251
}
252-
if !contains(severity.InfoLog, str, t) {
252+
if !contains(severity.InfoLog, str) {
253253
t.Error("Info failed")
254254
}
255255
}
@@ -263,17 +263,17 @@ func TestErrorWithOneOutput(t *testing.T) {
263263
logging.oneOutput = true
264264
defer logging.swap(logging.newBuffers())
265265
Error("test")
266-
if !contains(severity.ErrorLog, "E", t) {
266+
if !contains(severity.ErrorLog, "E") {
267267
t.Errorf("Error has wrong character: %q", contents(severity.ErrorLog))
268268
}
269-
if !contains(severity.ErrorLog, "test", t) {
269+
if !contains(severity.ErrorLog, "test") {
270270
t.Error("Error failed")
271271
}
272272
str := contents(severity.ErrorLog)
273-
if contains(severity.WarningLog, str, t) {
273+
if contains(severity.WarningLog, str) {
274274
t.Error("Warning failed")
275275
}
276-
if contains(severity.InfoLog, str, t) {
276+
if contains(severity.InfoLog, str) {
277277
t.Error("Info failed")
278278
}
279279
}
@@ -286,14 +286,14 @@ func TestWarning(t *testing.T) {
286286
setFlags()
287287
defer logging.swap(logging.newBuffers())
288288
Warning("test")
289-
if !contains(severity.WarningLog, "W", t) {
289+
if !contains(severity.WarningLog, "W") {
290290
t.Errorf("Warning has wrong character: %q", contents(severity.WarningLog))
291291
}
292-
if !contains(severity.WarningLog, "test", t) {
292+
if !contains(severity.WarningLog, "test") {
293293
t.Error("Warning failed")
294294
}
295295
str := contents(severity.WarningLog)
296-
if !contains(severity.InfoLog, str, t) {
296+
if !contains(severity.InfoLog, str) {
297297
t.Error("Info failed")
298298
}
299299
}
@@ -307,14 +307,14 @@ func TestWarningWithOneOutput(t *testing.T) {
307307
logging.oneOutput = true
308308
defer logging.swap(logging.newBuffers())
309309
Warning("test")
310-
if !contains(severity.WarningLog, "W", t) {
310+
if !contains(severity.WarningLog, "W") {
311311
t.Errorf("Warning has wrong character: %q", contents(severity.WarningLog))
312312
}
313-
if !contains(severity.WarningLog, "test", t) {
313+
if !contains(severity.WarningLog, "test") {
314314
t.Error("Warning failed")
315315
}
316316
str := contents(severity.WarningLog)
317-
if contains(severity.InfoLog, str, t) {
317+
if contains(severity.InfoLog, str) {
318318
t.Error("Info failed")
319319
}
320320
}
@@ -326,10 +326,10 @@ func TestV(t *testing.T) {
326326
defer logging.swap(logging.newBuffers())
327327
require.NoError(t, logging.verbosity.Set("2"))
328328
V(2).Info("test")
329-
if !contains(severity.InfoLog, "I", t) {
329+
if !contains(severity.InfoLog, "I") {
330330
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
331331
}
332-
if !contains(severity.InfoLog, "test", t) {
332+
if !contains(severity.InfoLog, "test") {
333333
t.Error("Info failed")
334334
}
335335
}
@@ -350,10 +350,10 @@ func TestVmoduleOn(t *testing.T) {
350350
t.Error("V enabled for 3")
351351
}
352352
V(2).Info("test")
353-
if !contains(severity.InfoLog, "I", t) {
353+
if !contains(severity.InfoLog, "I") {
354354
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
355355
}
356-
if !contains(severity.InfoLog, "test", t) {
356+
if !contains(severity.InfoLog, "test") {
357357
t.Error("Info failed")
358358
}
359359
}
@@ -375,7 +375,7 @@ func TestVmoduleOff(t *testing.T) {
375375
}
376376
}
377377

378-
func TestSetOutputDataRace(t *testing.T) {
378+
func TestSetOutputDataRace(*testing.T) {
379379
defer CaptureState().Restore()
380380
setFlags()
381381
defer logging.swap(logging.newBuffers())
@@ -965,7 +965,7 @@ func TestInfoObjectRef(t *testing.T) {
965965
for _, tt := range tests {
966966
t.Run(tt.name, func(t *testing.T) {
967967
Info(tt.ref)
968-
if !contains(severity.InfoLog, tt.want, t) {
968+
if !contains(severity.InfoLog, tt.want) {
969969
t.Errorf("expected %v, got %v", tt.want, contents(severity.InfoLog))
970970
}
971971
})
@@ -1465,7 +1465,7 @@ func TestLogFilter(t *testing.T) {
14651465
for _, tc := range testcases {
14661466
logging.newBuffers()
14671467
f.logFunc(tc.args...)
1468-
got := contains(f.severity, "[FILTERED]", t)
1468+
got := contains(f.severity, "[FILTERED]")
14691469
if got != tc.expectFiltered {
14701470
t.Errorf("%s filter application failed, got %v, want %v", f.name, got, tc.expectFiltered)
14711471
}
@@ -1804,7 +1804,7 @@ func (l *testLogr) reset() {
18041804
l.entries = []testLogrEntry{}
18051805
}
18061806

1807-
func (l *testLogr) Info(level int, msg string, keysAndValues ...interface{}) {
1807+
func (l *testLogr) Info(_ int, msg string, keysAndValues ...interface{}) {
18081808
l.mutex.Lock()
18091809
defer l.mutex.Unlock()
18101810
l.entries = append(l.entries, testLogrEntry{
@@ -1825,12 +1825,12 @@ func (l *testLogr) Error(err error, msg string, keysAndValues ...interface{}) {
18251825
})
18261826
}
18271827

1828-
func (l *testLogr) Init(info logr.RuntimeInfo) {}
1829-
func (l *testLogr) Enabled(level int) bool { return true }
1828+
func (l *testLogr) Init(logr.RuntimeInfo) {}
1829+
func (l *testLogr) Enabled(int) bool { return true }
18301830
func (l *testLogr) V(int) logr.Logger { panic("not implemented") }
18311831
func (l *testLogr) WithName(string) logr.LogSink { panic("not implemented") }
18321832
func (l *testLogr) WithValues(...interface{}) logr.LogSink { panic("not implemented") }
1833-
func (l *testLogr) WithCallDepth(depth int) logr.LogSink { return l }
1833+
func (l *testLogr) WithCallDepth(int) logr.LogSink { return l }
18341834

18351835
var _ logr.LogSink = &testLogr{}
18361836
var _ logr.CallDepthLogSink = &testLogr{}
@@ -1856,7 +1856,7 @@ func (l *callDepthTestLogr) WithCallDepth(depth int) logr.LogSink {
18561856
return l
18571857
}
18581858

1859-
func (l *callDepthTestLogr) Info(level int, msg string, keysAndValues ...interface{}) {
1859+
func (l *callDepthTestLogr) Info(_ int, msg string, keysAndValues ...interface{}) {
18601860
l.mutex.Lock()
18611861
defer l.mutex.Unlock()
18621862
// Add 2 to depth for the wrapper function caller and for invocation in
@@ -2201,12 +2201,12 @@ func TestSettingsDeepCopy(t *testing.T) {
22012201
},
22022202
},
22032203
}
2204-
copy := settings.deepCopy()
2205-
if !reflect.DeepEqual(settings, copy) {
2206-
t.Fatalf("Copy not identical to original settings. Original:\n %+v\nCopy: %+v", settings, copy)
2204+
clone := settings.deepCopy()
2205+
if !reflect.DeepEqual(settings, clone) {
2206+
t.Fatalf("Copy not identical to original settings. Original:\n %+v\nCopy: %+v", settings, clone)
22072207
}
22082208
settings.vmodule.filter[1].pattern = "x"
2209-
if copy.vmodule.filter[1].pattern == settings.vmodule.filter[1].pattern {
2209+
if clone.vmodule.filter[1].pattern == settings.vmodule.filter[1].pattern {
22102210
t.Fatal("Copy should not have shared vmodule.filter.")
22112211
}
22122212
}

0 commit comments

Comments
 (0)