Assume for a moment I have a Go package with numerous interfaces. For this example, I'd focus on one called Middleware
defined in middleware.go
:
type Middleware interface {
// some functions
}
I have some other parts of the system that uses it, so to better help test those parts of the system, I created a mock implementation by hand in mock_middleware.go
:
type MockMiddleware struct {
}
// implementations
When building the binary without tests, how do I exclude the mock classes from being built into the binary? I'm aware that middleware_test.go
will be excluded, but I'd don't want to name all my mocks with that convention so as not to confuse actual tests with implementations to support testing.
One way could be to use Build Constraints.
Go even supports a built in ignore
tag, but I'm not really sure of its interaction with the testing/benchmark toolchain:
To keep a file from being considered for the build:
// +build ignore