Skip to content

Commit

Permalink
fix revive issues
Browse files Browse the repository at this point in the history
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 }
                                     ^
  • Loading branch information
pohly committed Oct 26, 2023
1 parent a4f9060 commit ef25537
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 67 deletions.
4 changes: 3 additions & 1 deletion examples/output_test/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import (
"k8s.io/klog/v2/textlogger"
)

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

Expand Down
10 changes: 5 additions & 5 deletions internal/clock/testing/fake_clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,30 +258,30 @@ func (i *IntervalClock) Since(ts time.Time) time.Duration {

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

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

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

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

// Sleep is unimplemented, will panic.
func (*IntervalClock) Sleep(d time.Duration) {
func (*IntervalClock) Sleep(time.Duration) {
panic("IntervalClock doesn't implement Sleep")
}

Expand Down
70 changes: 35 additions & 35 deletions klog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func contents(s severity.Severity) string {
}

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

Expand All @@ -108,10 +108,10 @@ func TestInfo(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
Info("test")
if !contains(severity.InfoLog, "I", t) {
if !contains(severity.InfoLog, "I") {
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
}
if !contains(severity.InfoLog, "test", t) {
if !contains(severity.InfoLog, "test") {
t.Error("Info failed")
}
}
Expand Down Expand Up @@ -181,10 +181,10 @@ func TestStandardLog(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
stdLog.Print("test")
if !contains(severity.InfoLog, "I", t) {
if !contains(severity.InfoLog, "I") {
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
}
if !contains(severity.InfoLog, "test", t) {
if !contains(severity.InfoLog, "test") {
t.Error("Info failed")
}
}
Expand Down Expand Up @@ -239,17 +239,17 @@ func TestError(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
Error("test")
if !contains(severity.ErrorLog, "E", t) {
if !contains(severity.ErrorLog, "E") {
t.Errorf("Error has wrong character: %q", contents(severity.ErrorLog))
}
if !contains(severity.ErrorLog, "test", t) {
if !contains(severity.ErrorLog, "test") {
t.Error("Error failed")
}
str := contents(severity.ErrorLog)
if !contains(severity.WarningLog, str, t) {
if !contains(severity.WarningLog, str) {
t.Error("Warning failed")
}
if !contains(severity.InfoLog, str, t) {
if !contains(severity.InfoLog, str) {
t.Error("Info failed")
}
}
Expand All @@ -263,17 +263,17 @@ func TestErrorWithOneOutput(t *testing.T) {
logging.oneOutput = true
defer logging.swap(logging.newBuffers())
Error("test")
if !contains(severity.ErrorLog, "E", t) {
if !contains(severity.ErrorLog, "E") {
t.Errorf("Error has wrong character: %q", contents(severity.ErrorLog))
}
if !contains(severity.ErrorLog, "test", t) {
if !contains(severity.ErrorLog, "test") {
t.Error("Error failed")
}
str := contents(severity.ErrorLog)
if contains(severity.WarningLog, str, t) {
if contains(severity.WarningLog, str) {
t.Error("Warning failed")
}
if contains(severity.InfoLog, str, t) {
if contains(severity.InfoLog, str) {
t.Error("Info failed")
}
}
Expand All @@ -286,14 +286,14 @@ func TestWarning(t *testing.T) {
setFlags()
defer logging.swap(logging.newBuffers())
Warning("test")
if !contains(severity.WarningLog, "W", t) {
if !contains(severity.WarningLog, "W") {
t.Errorf("Warning has wrong character: %q", contents(severity.WarningLog))
}
if !contains(severity.WarningLog, "test", t) {
if !contains(severity.WarningLog, "test") {
t.Error("Warning failed")
}
str := contents(severity.WarningLog)
if !contains(severity.InfoLog, str, t) {
if !contains(severity.InfoLog, str) {
t.Error("Info failed")
}
}
Expand All @@ -307,14 +307,14 @@ func TestWarningWithOneOutput(t *testing.T) {
logging.oneOutput = true
defer logging.swap(logging.newBuffers())
Warning("test")
if !contains(severity.WarningLog, "W", t) {
if !contains(severity.WarningLog, "W") {
t.Errorf("Warning has wrong character: %q", contents(severity.WarningLog))
}
if !contains(severity.WarningLog, "test", t) {
if !contains(severity.WarningLog, "test") {
t.Error("Warning failed")
}
str := contents(severity.WarningLog)
if contains(severity.InfoLog, str, t) {
if contains(severity.InfoLog, str) {
t.Error("Info failed")
}
}
Expand All @@ -326,10 +326,10 @@ func TestV(t *testing.T) {
defer logging.swap(logging.newBuffers())
require.NoError(t, logging.verbosity.Set("2"))
V(2).Info("test")
if !contains(severity.InfoLog, "I", t) {
if !contains(severity.InfoLog, "I") {
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
}
if !contains(severity.InfoLog, "test", t) {
if !contains(severity.InfoLog, "test") {
t.Error("Info failed")
}
}
Expand All @@ -350,10 +350,10 @@ func TestVmoduleOn(t *testing.T) {
t.Error("V enabled for 3")
}
V(2).Info("test")
if !contains(severity.InfoLog, "I", t) {
if !contains(severity.InfoLog, "I") {
t.Errorf("Info has wrong character: %q", contents(severity.InfoLog))
}
if !contains(severity.InfoLog, "test", t) {
if !contains(severity.InfoLog, "test") {
t.Error("Info failed")
}
}
Expand All @@ -375,7 +375,7 @@ func TestVmoduleOff(t *testing.T) {
}
}

func TestSetOutputDataRace(t *testing.T) {
func TestSetOutputDataRace(*testing.T) {
defer CaptureState().Restore()
setFlags()
defer logging.swap(logging.newBuffers())
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestInfoObjectRef(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Info(tt.ref)
if !contains(severity.InfoLog, tt.want, t) {
if !contains(severity.InfoLog, tt.want) {
t.Errorf("expected %v, got %v", tt.want, contents(severity.InfoLog))
}
})
Expand Down Expand Up @@ -1465,7 +1465,7 @@ func TestLogFilter(t *testing.T) {
for _, tc := range testcases {
logging.newBuffers()
f.logFunc(tc.args...)
got := contains(f.severity, "[FILTERED]", t)
got := contains(f.severity, "[FILTERED]")
if got != tc.expectFiltered {
t.Errorf("%s filter application failed, got %v, want %v", f.name, got, tc.expectFiltered)
}
Expand Down Expand Up @@ -1804,7 +1804,7 @@ func (l *testLogr) reset() {
l.entries = []testLogrEntry{}
}

func (l *testLogr) Info(level int, msg string, keysAndValues ...interface{}) {
func (l *testLogr) Info(_ int, msg string, keysAndValues ...interface{}) {
l.mutex.Lock()
defer l.mutex.Unlock()
l.entries = append(l.entries, testLogrEntry{
Expand All @@ -1825,12 +1825,12 @@ func (l *testLogr) Error(err error, msg string, keysAndValues ...interface{}) {
})
}

func (l *testLogr) Init(info logr.RuntimeInfo) {}
func (l *testLogr) Enabled(level int) bool { return true }
func (l *testLogr) Init(logr.RuntimeInfo) {}
func (l *testLogr) Enabled(int) bool { return true }
func (l *testLogr) V(int) logr.Logger { panic("not implemented") }
func (l *testLogr) WithName(string) logr.LogSink { panic("not implemented") }
func (l *testLogr) WithValues(...interface{}) logr.LogSink { panic("not implemented") }
func (l *testLogr) WithCallDepth(depth int) logr.LogSink { return l }
func (l *testLogr) WithCallDepth(int) logr.LogSink { return l }

var _ logr.LogSink = &testLogr{}
var _ logr.CallDepthLogSink = &testLogr{}
Expand All @@ -1856,7 +1856,7 @@ func (l *callDepthTestLogr) WithCallDepth(depth int) logr.LogSink {
return l
}

func (l *callDepthTestLogr) Info(level int, msg string, keysAndValues ...interface{}) {
func (l *callDepthTestLogr) Info(_ int, msg string, keysAndValues ...interface{}) {
l.mutex.Lock()
defer l.mutex.Unlock()
// Add 2 to depth for the wrapper function caller and for invocation in
Expand Down Expand Up @@ -2201,12 +2201,12 @@ func TestSettingsDeepCopy(t *testing.T) {
},
},
}
copy := settings.deepCopy()
if !reflect.DeepEqual(settings, copy) {
t.Fatalf("Copy not identical to original settings. Original:\n %+v\nCopy: %+v", settings, copy)
clone := settings.deepCopy()
if !reflect.DeepEqual(settings, clone) {
t.Fatalf("Copy not identical to original settings. Original:\n %+v\nCopy: %+v", settings, clone)
}
settings.vmodule.filter[1].pattern = "x"
if copy.vmodule.filter[1].pattern == settings.vmodule.filter[1].pattern {
if clone.vmodule.filter[1].pattern == settings.vmodule.filter[1].pattern {
t.Fatal("Copy should not have shared vmodule.filter.")
}
}
Loading

0 comments on commit ef25537

Please sign in to comment.