Skip to content

new checker 'mock-expect'#257

Open
d0ubletr0uble wants to merge 4 commits intoAntonboom:masterfrom
d0ubletr0uble:feat/mock-expect
Open

new checker 'mock-expect'#257
d0ubletr0uble wants to merge 4 commits intoAntonboom:masterfrom
d0ubletr0uble:feat/mock-expect

Conversation

@d0ubletr0uble
Copy link
Copy Markdown

Closes #250

@Antonboom
Copy link
Copy Markdown
Owner

Antonboom commented Sep 14, 2025

Hi, @d0ubletr0uble

Thank you for contributing!

Maybe you can suggest some large code bases with using of mockery?
(to test the checker)

P.S. I am personally a fan of https://github.com/uber-go/mock and not familiar with https://github.com/vektra/mockery

@d0ubletr0uble
Copy link
Copy Markdown
Author

https://github.com/kyma-project/eventing-manager is a good candidate to test the linter.

git clone --depth=1 https://github.com/kyma-project/eventing-manager
cd eventing-manager

testifylint -disable-all -enable mock-expect ./...
testifylint -disable-all -enable mock-expect -fix ./...

It even detects cases where .GetSecret() and .Stop() methods break interface contract since you can pass anything to .On() method. Such mocks are registered but will never be called.

Linter does break one .PatchApply(...).Run(...) call where .Run(...) argument types need to be updated. Will see if I can detect such cases and skip autofix for them.

Also, it currently ignores gingo test suites. I'll check what can be done about that.

@d0ubletr0uble
Copy link
Copy Markdown
Author

Added gingo support by dropping restriction to check only Test functions.

https://github.com/pluralsh/console is a code base that uses gingo test suites and mockery.

git clone --depth=1 https://github.com/pluralsh/console
cd console/go/controller

testifylint -disable-all -enable mock-expect ./...
testifylint -disable-all -enable mock-expect -fix ./...

It does break cases where too many arguments were passed into original .On() function call.

@d0ubletr0uble
Copy link
Copy Markdown
Author

Made the linter to skip calls with .Run(...) in the chain. Fixes the issue where it would mess up the arguments.

@thespags
Copy link
Copy Markdown

thespags commented Feb 4, 2026

Hi. I'm curious as to the status. This would be great to get into testifylint.

@d0ubletr0uble
Copy link
Copy Markdown
Author

All done on my end, just waiting for feedback or a merge. You can use the fork in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mock-expect: suggest using EXPECT

3 participants