Skip to content

Commit

Permalink
chore: improve MockLog
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 24, 2024
1 parent 91a8f21 commit b6cec67
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/golinters/gofmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ index 0000000..6399915
+// line
`

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

var noChanges []Change
testDiffProducesChanges(t, log, diff, noChanges...)
Expand Down
12 changes: 6 additions & 6 deletions pkg/lint/lintersdb/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ func TestValidator_validatePresets_error(t *testing.T) {
}

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

m, err := NewManager(log, nil, NewLinterBuilder())
require.NoError(t, err)
Expand Down
45 changes: 45 additions & 0 deletions pkg/logutils/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,48 @@ func (m *MockLog) Child(name string) Log {
func (m *MockLog) SetLevel(level LogLevel) {
m.Called(level)
}

func (m *MockLog) OnFatalf(format string, args ...any) *MockLog {
arguments := []any{format}
arguments = append(arguments, args...)

m.On("Fatalf", arguments...)

return m
}

func (m *MockLog) OnPanicf(format string, args ...any) *MockLog {
arguments := []any{format}
arguments = append(arguments, args...)

m.On("Panicf", arguments...)

return m
}

func (m *MockLog) OnErrorf(format string, args ...any) *MockLog {
arguments := []any{format}
arguments = append(arguments, args...)

m.On("Errorf", arguments...)

return m
}

func (m *MockLog) OnWarnf(format string, args ...any) *MockLog {
arguments := []any{format}
arguments = append(arguments, args...)

m.On("Warnf", arguments...)

return m
}

func (m *MockLog) OnInfof(format string, args ...any) *MockLog {
arguments := []any{format}
arguments = append(arguments, args...)

m.On("Infof", arguments...)

return m
}

0 comments on commit b6cec67

Please sign in to comment.