Skip to content

Commit aed93f3

Browse files
committed
chore: improve MockLog
1 parent e43d1f7 commit aed93f3

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

pkg/golinters/gofmt_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ index 0000000..6399915
128128
+// line
129129
`
130130

131-
log := logutils.NewMockLog()
132-
log.On("Infof", "The diff contains only additions: no original or deleted lines: %#v", mock.Anything)
131+
log := logutils.NewMockLog().
132+
OnInfof("The diff contains only additions: no original or deleted lines: %#v", mock.Anything)
133133

134134
var noChanges []Change
135135
testDiffProducesChanges(t, log, diff, noChanges...)

pkg/lint/lintersdb/validator_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ func TestValidator_validatePresets_error(t *testing.T) {
218218
}
219219

220220
func TestValidator_alternativeNamesDeprecation(t *testing.T) {
221-
log := logutils.NewMockLog()
222-
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "vet", "govet")
223-
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "vetshadow", "govet")
224-
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "logrlint", "loggercheck")
225-
log.On("Warnf", "The linter name %q is deprecated. It has been splited into: %s.", "megacheck", "gosimple, staticcheck, unused")
226-
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "gas", "gosec")
221+
log := logutils.NewMockLog().
222+
OnWarnf("The linter name %q is deprecated. It has been renamed to: %s.", "vet", "govet").
223+
OnWarnf("The linter name %q is deprecated. It has been renamed to: %s.", "vetshadow", "govet").
224+
OnWarnf("The linter name %q is deprecated. It has been renamed to: %s.", "logrlint", "loggercheck").
225+
OnWarnf("The linter name %q is deprecated. It has been splited into: %s.", "megacheck", "gosimple, staticcheck, unused").
226+
OnWarnf("The linter name %q is deprecated. It has been renamed to: %s.", "gas", "gosec")
227227

228228
m, err := NewManager(log, nil, NewLinterBuilder())
229229
require.NoError(t, err)

pkg/logutils/mock.go

+45
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,48 @@ func (m *MockLog) Child(name string) Log {
4545
func (m *MockLog) SetLevel(level LogLevel) {
4646
m.Called(level)
4747
}
48+
49+
func (m *MockLog) OnFatalf(format string, args ...any) *MockLog {
50+
arguments := []any{format}
51+
arguments = append(arguments, args...)
52+
53+
m.On("Fatalf", arguments...)
54+
55+
return m
56+
}
57+
58+
func (m *MockLog) OnPanicf(format string, args ...any) *MockLog {
59+
arguments := []any{format}
60+
arguments = append(arguments, args...)
61+
62+
m.On("Panicf", arguments...)
63+
64+
return m
65+
}
66+
67+
func (m *MockLog) OnErrorf(format string, args ...any) *MockLog {
68+
arguments := []any{format}
69+
arguments = append(arguments, args...)
70+
71+
m.On("Errorf", arguments...)
72+
73+
return m
74+
}
75+
76+
func (m *MockLog) OnWarnf(format string, args ...any) *MockLog {
77+
arguments := []any{format}
78+
arguments = append(arguments, args...)
79+
80+
m.On("Warnf", arguments...)
81+
82+
return m
83+
}
84+
85+
func (m *MockLog) OnInfof(format string, args ...any) *MockLog {
86+
arguments := []any{format}
87+
arguments = append(arguments, args...)
88+
89+
m.On("Infof", arguments...)
90+
91+
return m
92+
}

0 commit comments

Comments
 (0)