-
Notifications
You must be signed in to change notification settings - Fork 39
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
Mocks aren't generated for type aliases #106
Comments
Hi! Thanks for raising issue, but imo i dont see it as a minimock issue. Minimock is defined to generate mocks from interfaces, not from interface aliases. I dont see where such behaviour would be useful |
@zcolleen the inconvenience can be demonstrated by this case: @Wani4ka uses a shortcut to generate mocks for all interfaces from a certain package: A couple of workarounds that I can suggest:
for the interface types this should not make a difference in most cases. I'm not sure that this makes any sense: type Sampler2 Sampler
type Sampler3 = Sampler But this totally makes sense to me: type MyReaderAlias = io.Reader
type MyReaderType io.Reader I think type aliases are more important issue here because despite the fact that interface types themselves are interchangeable, the derived container types like []InterfaceType or map[something]InterfaceTypes are not. |
@zcolleen Hi! Long time no see. Actually we have such an isssue with our RTC Client (if you remember what is it :D) — we have private interfaces for our own needs and we have type alias for it and it is user facing public type alias. So here we are. Mocks are generated based on internal/ paths. |
@kavu hey! Glad to hear from you. I see now that this feature is highly requested and we will definitely think of implementing this feature (although i don't quiet remember the mocking issue with RTC Client). The only consern that i have is that we will change behaviour by default, which can result in unexpected manner for somebody. May be we should add this behaviour as an optional flag? WDYT guys? |
Hey guys, opened pr #109 for this feature |
feauture is available in v3.3.14 release |
Due to AST interpreting interface aliases as aliases, and not as interfaces, minimock skips interface aliases and doesn't generate mocks for them.
For testing it out I used the latest version of minimock cloned directly from this repository.
Here are the steps to reproduce:
./example/types.go
minimock -i "./example.*"
I expect all five interfaces to be generated, but only the first one and the last one is generated, which we can see from the command output:
$ go run ./cmd/minimock -i "./example.*" minimock: ./sampler_mock_test.go minimock: ./read_write_seek_closer_mock_test.go
The text was updated successfully, but these errors were encountered: