You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is a package only consisting of generated codes the mockery won't generate mocks for the interfaces. For example, we use SQLC which is a code generator for SQL queries when the package specified for generated querier has only SQLC-generated files the mockery skips the package and doesn't create any mocks.
In your go project create a new package let's call it somepackage
In the package create a new go file called somefile.go
In the file paste a code like below
now run mockery
// Code generated by someGenerator . DO NOT EDIT.package somepackage
typeMyRandomInterfaceinterface {
SomeRandomFunc()
}
Expected Behavior
a file named mock_myrandominterface.go to be created
Actual Behavior
nothing happens
But If you create a file that isn't a generated code and put it beside the first file even if its empty(only contains package name) the mocks will be created. I think this has something to do with mocks packages and there is an condition not the check packages with only generated files.
The text was updated successfully, but these errors were encountered:
It requires you to have at least one non-test go file. If you don't have that, packages.Load assumes there is nothing that you could be importing from that package, and as an optimization I guess it simply doesn't return any metadata about the package. The solution is to create one non-test go file so it induces it to download.
I've tried many ways to fix this but it doesn't seem possible. I'm open to ideas.
@LandonTClipp It's not a problem with test files. I think I may have explained it poorly. It's a problem with generated files.
I changed the description and clarified the problem.
Okay I understand your problem now. This is also mentioned here: #681, an issue with protobuf clients. We definitely need to fix this. I'll close this issue as a duplicate and we can track the linked issue.
Description
When there is a package only consisting of generated codes the mockery won't generate mocks for the interfaces. For example, we use SQLC which is a code generator for SQL queries when the package specified for generated querier has only SQLC-generated files the mockery skips the package and doesn't create any mocks.
Mockery Version
v2.32.2
(I tried v2.30.2 too)
Golang Version
go 1.20
Installation Method
Mockery Config
Steps to Reproduce
somepackage
somefile.go
Expected Behavior
a file named
mock_myrandominterface.go
to be createdActual Behavior
nothing happens
But If you create a file that isn't a generated code and put it beside the first file even if its empty(only contains package name) the mocks will be created. I think this has something to do with mocks packages and there is an condition not the check packages with only generated files.
The text was updated successfully, but these errors were encountered: