mock
mock copied to clipboard
invalid package default when destination is in the same directory
The default package name is mock_<CURRENT_PACKAGE>. This is fine if the destination is outside the current directory, however it is invalid if you place it in the same directory as the source. A valid package would have to be either <CURRENT_PACKAGE> or <CURRENT_PACKAGE>_test.
Note that this will create a import cycle
mockgen -destination app_test.go -source=app.pb.go -package=main
package main
import (
x "."
context "context"
gomock "github.com/golang/mock/gomock"
grpc "google.golang.org/grpc"
reflect "reflect"
)
Suggest by default to not use x "." so that one can generate mock files in the same directory without using a subdirectory
@gertcuykens this looks related to #230. Are you using modules outside the go gopath when you get these results?
Yes correct
You are right the default is not great. An option here might be to default the package name to <CURRENT_PACKAGE>_test if both source and dest files are in the same location. That way we don't change peoples imports with the current behavior, but we give people code that will compile if they attempt to generate in the same directory as the source.