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

cannot write tests in package being tested due to import cycle #210

Open
ideasculptor opened this issue Oct 5, 2022 · 0 comments
Open

Comments

@ideasculptor
Copy link

counterfeiter fakes include a line at the bottom which assigns a pointer to the fake to a variable declared as type of interface being mocked. This is a great way to ensure that the counterfeit actually implements the specified interface so that the compiler will generate an error when the interface changes, but it means that you cannot implement a test that depends on the counterfeit implementation within the package itself, because it forces a dependency on that package into packagefakes package.

This means that every time we run go generate, we must also run a script which strips that line out of each generated file. There should be a command line option to skip adding that line to the counterfeit, or which specifies the file to add it to. If I want to detect that the interface is no longer satisfied, I can add such an assignment myself, rather than having the code generator break all test code that adheres to the common pattern of putting tests in the same package as the code being tested (in order to gain access to non-exported fields and methods, which can greatly simplify testing). But it would be even better to have the generator add the line to a specified file so that we can generate those checks in the package being tested rather than in the packagefakes package where it causes an import cycle.

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

No branches or pull requests

1 participant