mockery: Unable to generate interface type from another interface
Description
Hi, I wanted to write some mock for my interface :
type ResponseLessUseCase[M any] interface {
Execute(message *M) *errors.Error
}
type SendEmailVerificationUseCaseInterface ResponseLessUseCase[usermessages.SendEmailVerificationMessage]
But only the mock for ResponseLessUseCase was created, maybe I miss something ?
Mockery Version
v2.43.2
Golang Version
v1.22.3
Installation Method
- Binary Distribution
- Docker
- brew
- go install
- Other: [specify]
Steps to Reproduce
- Install go & mockery last versions
- Write a golang file that include a generic interface and another interface that is typed as your generic interface
- Run mockery
Expected Behavior
A mock for the interface that inherit the generic one
Actual Behavior
Only the mock of the generic interface
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (8 by maintainers)
Well this is hilarious. The Go AST considers this to be an index expression:
*ast.IndexExpr. Mockery does not seeSendEmailVerificationUseCaseInterfaceas an interface type because of this. I can successfully induce mockery to generate a mock for it by telling it to include*ast.IndexExprthe list of types it generates mocks for (currently only interfaces and functions), but I’m not entirely sure on the implications of this. I need to think about it.There’s three ways we could resolve this:
*ast.IndexExpr. This is highly risky as I’m unsure the ways in which this might break.PR: https://github.com/vektra/mockery/pull/790