How to use shorthand generate directive for external packages?
dionysius opened this issue · 1 comments
I generate fakes from external interfaces so I can write tests against it and define a behaviour of said interface during tests.
After upgrading counterfeiter I get this warning, which is indeed true that it takes long:
WARNING: Invoking counterfeiter multiple times from "go generate" is slow.
Consider using counterfeiter:generate directives to speed things up.
See https://github.com/maxbrunsfeld/counterfeiter#step-2b---add-counterfeitergenerate-directives for more information.
So I tried to change the generation to the suggested way as written in the Readme. But the Readme also shows only an example for own interfaces where you write it directly in the source files.
How should the generate directive look for external interfaces?
package lxf
// lxdfakes
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o lxdfakes/fake_operation.go github.com/lxc/lxd/client.Operation
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o lxdfakes/fake_remote_operation.go github.com/lxc/lxd/client.RemoteOperation
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o lxdfakes/fake_server.go github.com/lxc/lxd/client.Server
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o lxdfakes/fake_image_server.go github.com/lxc/lxd/client.ImageServer
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o lxdfakes/fake_container_server.go github.com/lxc/lxd/client.ContainerServer
+//counterfeiter:generate -o lxdfakes/fake_operation.go github.com/lxc/lxd/client.Operation
+//counterfeiter:generate -o lxdfakes/fake_remote_operation.go github.com/lxc/lxd/client.RemoteOperation
+//counterfeiter:generate -o lxdfakes/fake_server.go github.com/lxc/lxd/client.Server
+//counterfeiter:generate -o lxdfakes/fake_image_server.go github.com/lxc/lxd/client.ImageServer
+//counterfeiter:generate -o lxdfakes/fake_container_server.go github.com/lxc/lxd/client.ContainerServer
Right now with above changes, I don't see any generation happening anymore. I've seen that there's also #195, but this doesn't explain that the generation is not doing anything.
Oh wait, i just found the comment:
// You only need one of these per package!
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate// You will add lots of directives like these in the same package...
//counterfeiter:generate . MySpecialInterface
Yes, that did the trick! RTFM <3