-
Notifications
You must be signed in to change notification settings - Fork 69
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
(v5) WithContext types are troublesome to mock #378
Comments
@fbiville any thoughts on this? |
Hi @lukestoward, first of all: thanks for trying out the preview version and providing feedbck! The unexported Note that the hypothetical fix would only applied to the |
Hi @fbiville, that shouldn't be a problem. Thanks for taking a look and let me know how you get on. |
Hello, I think #379 fixes it but it would be great if you could confirm it. |
Hi @fbiville, this does indeed look like it's fixed the issue. One caveat is that I am still unable to use vektra/mockery as there is an issue with providing an implementation for an interface with unexported methods. This is more a limitation with mockery, since it is possible to satisfy an interface with unexported methods in a different package by embedding the interface directly in your type. That said it's a minor thing, but I will have to manually implement my own mocks. (unless I'm missing an option with the mock-gen tool 🤔) Anyway, thank you for addressing this issue. 👍 |
Back from sick leave 🐛 |
I've been experimenting with the Context aware v5.0.0 preview and I've ran into some issues when trying to write unit tests.
In version 4.X of the Go package interface types such as
Result
,Session
andTransaction
have exported methods only. Which can easily be mocked using tools such as vektra/mockery. However, when using version 5.0.0-preview, the new context aware typesResultWithContext
,SessionWithContext
andTransactionWithContext
contain new unexported methods such aslegacy()
which in some cases return unexported types such as*result
.Whilst
mockery
can still create mocks for the interfaces, I am unable to use the mockResultWithContext
as thelegacy()
method has an unexported return value*result
.I get the following error when building using the mock of
ResultWithContext
:Would it be possible to remove the unexported methods on those interfaces, or more importantly, remove the unexported return value
*result
.If you would like to generate the mock yourself, run the following:
$ go install github.com/vektra/mockery/v2@latest $ mockery --with-expecter --exported --dir $(go list -m -f '{{ .Dir }}' github.com/neo4j/neo4j-go-driver/v5)/neo4j --name ResultWithContext --output mocks
The text was updated successfully, but these errors were encountered: