Documentation ¶
Overview ¶
Package smock exposes methods to generate new mocks for interfaces in a go project.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateMocks ¶
GenerateMocks creates mock objects for all interfaces found in the module. Will search for a "go.mod" file traversing up the filesystem. Fails if no mod file is found.
Returns a list of file paths to the generated mock objects. Optionally pass multiple Option as parameter.
Is meant to be used within a short go main function which will execute GenerateMocks. Annotate with '//go:generate go run ./' to allow mock generation via the 'go generate' command. The advantage of doing so is that no additional software needs to be installed to generate the mocks since smock is already included in the module as library. This simplifies the project setup because no additional binaries needs to be installed on the machine which generates the mocks. The mock files might then also be excluded from your repository by a adding '*/**/*_mock' to the '.gitignore' file.
The following code snippet shows how smock can be used as a small binary within a go project:
package main import ( "github.com/becheran/smock/smock" ) //go:generate go run ./ func main() { smock.GenerateMocks() }
Types ¶
type Option ¶
type Option func(*opt)
Option which can be passed to GenerateMocks using one of the constructors.
func WithDebugLog ¶
func WithDebugLog() Option
WithDebugLog enables debug logging which prints debug logs to the console
func WithInterfaceNameAllowList ¶
WithInterfaceNameAllowList sets a list of interface names which shall be used for mock creation. Is incompatible with the WithInterfaceNameDenyList option.
Uses the wildcard syntax described in http://github.com/becheran/wildmatch-go for string matches.
func WithInterfaceNameDenyList ¶
WithInterfaceNameDenyList sets a list of interface names which shall not be used for mock creation. Is incompatible with the WithInterfaceNameAllowList option.
Uses the wildcard syntax described in http://github.com/becheran/wildmatch-go for string matches.
func WithUnexportedInterfaces ¶
func WithUnexportedInterfaces() Option
WithUnexportedInterfaces enables generation of unexported interfaces