golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.28k stars 610 forks source link

proposal: default _mock suffix package name inline with _test suffix package for Go2 #254

Closed gertcuykens closed 5 years ago

gertcuykens commented 5 years ago

Currently the the default package mock_name is the oposite of package name_test naming convention. Can this be revisited so we have name_mock and name_test and also take some time to investigate if it would be interesting for Go2 to add _mock files into the specification espacialy guidelines on go modules mocking?

This is how I use mockgen at the moment but others use totally diferent approach, I believe mocking is important enough to have a bit more direct specifications in Go2.

package health

//go:generate protoc -I . health.proto --go_out=plugins=grpc:.
//go:generate protoc -I . health.proto --descriptor_set_out=health.protoset --include_imports
//go:generate mockgen -destination health_mock/health.go -source=health.pb.go -package=health_mock
syntax = "proto3";

package health;

message HealthCheckRequest {
  string service = 1;
}

message HealthCheckResponse {
  enum ServingStatus {
    UNKNOWN = 0;
    SERVING = 1;
    NOT_SERVING = 2;
  }
  ServingStatus status = 1;
}

service Health {
  rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
}
poy commented 5 years ago

@gertcuykens Thanks for the proposal.

gertcuykens commented 5 years ago

If you can make it so it follows the go test guidelines and generated code nothing more then a _test package or _test.go file then no proposal is needed. I maybe was thinking there where other details that doesn't fit in go test but your right, if you can make changes so it's clear _test packages and _test files are the way to go that would be awesome, because everybody will be doing it the same way if you guide them to do so