$ head -n 17 /Users/landon/git/LandonTClipp/mockery/internal/fixtures/mocks_test.go
// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
package test
import (
"encoding/json"
"io"
"net/http"
"unsafe"
mock "github.com/stretchr/testify/mock"
http1 "github.com/vektra/mockery/v3/internal/fixtures/12345678/http"
"github.com/vektra/mockery/v3/internal/fixtures/constraints"
http0 "github.com/vektra/mockery/v3/internal/fixtures/http"
test "github.com/vektra/mockery/v3/internal/fixtures/redefined_type_b"
)
Extended Example
A more complex configuration example can be seen below:
YAML
all:Falsetemplate-data:boilerplate-file:./path/to/boilerplate.txttemplate:testifypackages:github.com/vektra/example:config:# Make use of the template variables to place the mock in the same# directory as the original interface.dir:"{{.InterfaceDir}}"filename:"mocks_test.go"outpkg:"{{.PackageName}}_test"structname:"{{.Mock}}{{.InterfaceName}}"interfaces:Foo:Bar:config:# Make it unexported insteadstructname:"mock{{.InterfaceName}}"Baz:# Create two mock implementations of Baz with different names.configs:-filename:"mocks_baz_one_test.go"structname:"MockBazOne"-filename:"mocks_baz_two_test.go"structname:"MockBazTwo"io:config:dir:path/to/io/mocksfilename:"mocks_io.go"
These are the highlights of the config scheme:
The parameters are merged hierarchically
There are a number of template variables available to generalize config values.
The style of mock to be generated is specified using the template parameter.
Generate all interfaces for the specified packages.
_anchors
{}
Unused by mockery, but allowed in the config schema so that you may define arbitrary yaml anchors.
config
""
Set the location of the mockery config file.
dir
"{{.InterfaceDir}}"
The directory where the mock file will be outputted to.
exclude-subpkg-regex
[]
A list of regular expressions that denote which subpackages should be excluded when recursive:true
exclude-interface-regex
""
When set along with include-interface-regex, then interfaces which match include-interface-regex but also match exclude-interface-regex will not be generated. If all is set, or if include-interface-regex is not set, then exclude-interface-regex has no effect.
filename
"mocks_test.go"
The name of the file the mock will reside in.
force-file-write
true
When set to force-file-write:true, mockery will forcibly overwrite any existing files. Otherwise, it will fail if the output file already exists.
formatter
"goimports"
The formatter to use on the rendered template. Choices are: gofmt, goimports, noop.
include-interface-regex
""
When set, only interface names that match the expression will be generated. This setting is ignored if all: True is specified in the configuration. To further refine the interfaces generated, use exclude-interface-regex.
log-level
"info"
Set the level of the logger
structname
"{{.Mock}}{{.InterfaceName}}"
The name of the generated interface implementation.
packages
null
A dictionary containing configuration describing the packages and interfaces to generate mocks for.
pkgname
"{{.SrcPackageName}}"
The packagename given to the generated mock files.
recursive
false
When set to true on a particular package, mockery will recursively search for all sub-packages and inject those packages into the config map.
A space-separated list of additional build tags to load packages.
require-template-schema-exists
true
If set to true and the schema failed to download, mockery will fail. Otherwise, mockery will not attempt to download the file nor do any schema validation.
template
""
The template to use. The choices are defined in the Templates section.
template-data
{}
A map[string]any that provides arbitrary options to the template. Each template will have a different set of accepted keys. Refer to each template's documentation for more details.
template-schema
"{{.Template}}.schema.json"
The URL of the JSON schema to apply to the template-data parameter. See the template docs for more details.
Config can not only be specified from the .yml file, but also from CLI parameters (where available) and environment variables. For example, specifying a boolean value for a particular parameter called enable-feature from each config source would look like this:
source
value
command line
--enable-feature=true
Environment variable
MOCKERY_ENABLE_FEATURE=True
yaml
enable-feature:True
Config is loaded from each source in the following order: