Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vektra/mockery #24

Open
ccoVeille opened this issue Feb 8, 2025 · 5 comments · May be fixed by #26
Open

Support vektra/mockery #24

ccoVeille opened this issue Feb 8, 2025 · 5 comments · May be fixed by #26

Comments

@ccoVeille
Copy link

ccoVeille commented Feb 8, 2025

Please see discussion here

You can take a look at the PR I made and you could reuse

Please also find the explanations why I closed my PR in mockery repository

@bhundven
Copy link
Owner

bhundven commented Feb 9, 2025

I'm just curious how this would be used.
I wasn't familiary with mockery, so I had to read into that one a bit.
It seems to me that this would be used in a pre-commit like this (.pre-commit-config.yaml):

repos:
  - repo: https://github.com/bhundven/golang-pre-commit
    rev: v1
    hooks:
      - id: go-build
      - id: go-mockery
      - id: go-unit-tests

right? Or mockery runs the tests?

@ccoVeille
Copy link
Author

Mockery is about generating code that can be used in tests.

It generates it from code my looking at interfaces. It's a kind of go:generate

Mocks can be used in tests of the package itself, but also by code using the Go module as library in external code.

For this reason, it's important to update code from source.

The best example I'm able to think about is to consider an interface had two methods

type Whatever interface {
	Foo() string
	Bar() string
}

So the code and mocks supported Foo() and Bar()

Now the maintainer removes Bar() from the interface, if mockery is not called, the Mock will still have Bar()

Tests will pass for people using mocked Bar in their tests, but Bar was removed, so their code will be broken without them to know.

TL; DR; Using it as a pre-commit hook is important because it will make sure to update the mocks before committing

Mockery doesn't launch test, it generates code that can be used by the tests

There is no dependency between running test, using go build and launching mockery

The user defining the pre-commit hooks in their .pre-commit-config.yaml will be the one who knows what they need to launch and in what order

@bhundven
Copy link
Owner

bhundven commented Feb 9, 2025

Gotcha. I'll get something for you to review tomorrow.

@ccoVeille
Copy link
Author

Please also consider including the people who were looking for this feature. I mentioned them in this message

@ccoVeille ccoVeille changed the title Support mockery Support vektra/mockery Feb 9, 2025
bhundven added a commit that referenced this issue Feb 9, 2025
Closes: #24

Signed-off-by: Bryan Hundven <[email protected]>
@bhundven bhundven linked a pull request Feb 9, 2025 that will close this issue
@bhundven
Copy link
Owner

bhundven commented Feb 9, 2025

Test adding mockery:

repos:
  - repo: https://github.com/bhundven/golang-pre-commit
    rev: feat/mockery
    hooks:
      - id: generate-mockery

Let me know.

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 a pull request may close this issue.

2 participants