Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonTClipp committed Dec 26, 2024
1 parent d416405 commit 3740344
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 174 deletions.
231 changes: 88 additions & 143 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -1,147 +1,92 @@
disable-version-string: True
mockname: "{{.InterfaceName}}Mock"
filename: "moq_test.go"
template: moq
dir: "mocks/moq/{{.PackagePath}}"
formatter: "goimports"

mockname: "{{.InterfaceName}}"
filename: "{{.MockName}}_mock.go"
outpkg: mocks
tags: "custom2"
issue-845-fix: True
_anchors: &inpackage_config
all: True
dir: "{{.InterfaceDir}}"
mockname: "Mock{{.InterfaceName}}"
outpkg: "{{.PackageName}}_test"
filename: "mock_{{.InterfaceNameSnake}}_test.go"
packages:
github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment:
config:
mock-build-tags: "custom3 && (!windows || !darwin || !freebsd)"
disable-version-string: true
interfaces:
IfaceWithCustomBuildTagInComment:
github.com/vektra/mockery/v2/pkg:
interfaces:
TypesPackage:
github.com/vektra/mockery/v2/pkg/fixtures:
config:
include-regex: '.*'
exclude-regex: 'RequesterGenerics|UnsafeInterface|requester_unexported'
outpkg: test
filename: "moq_fixtures_test.go"
template-data:
with-resets: true
skip-ensure: true
stub-impl: false
#quiet: False
#disable-version-string: True
#with-expecter: True
#mockname: "{{.InterfaceName}}"
#filename: "{{.MockName}}_mock.go"
#outpkg: mocks
#tags: "custom2"
#issue-845-fix: True
#resolve-type-alias: False
#_anchors: &inpackage_config
# all: True
# dir: "{{.InterfaceDir}}"
# mockname: "Mock{{.InterfaceName}}"
# outpkg: "{{.PackageName}}_test"
# filename: "mock_{{.InterfaceNameSnake}}_test.go"
# inpackage: False
#packages:
# github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment:
# config:
# mock-build-tags: "custom3 && (!windows || !darwin || !freebsd)"
# disable-version-string: true
# interfaces:
# IfaceWithCustomBuildTagInComment:
# github.com/vektra/mockery/v2/pkg:
# interfaces:
# TypesPackage:
# github.com/vektra/mockery/v2/pkg/fixtures:
# config:
# all: True
# interfaces:
# RequesterArgSameAsNamedImport:
# RequesterVariadic:
# config:
# with-expecter: False
# configs:
# - mockname: RequesterVariadicOneArgument
# unroll-variadic: False
# - mockname: RequesterVariadic
# unroll-variadic: True
# Expecter:
# config:
# with-expecter: True
# configs:
# - mockname: ExpecterAndRolledVariadic
# unroll-variadic: False
# - mockname: Expecter
# unroll-variadic: True
# RequesterReturnElided:
# VariadicNoReturnInterface:
# config:
# with-expecter: True
# unroll-variadic: False
# # Replace generic params with a new constraint and a new fixed value
# ReplaceGeneric:
# config:
# replace-type:
# - github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGeneric[-TImport]=github.com/vektra/mockery/v2/pkg/fixtures/redefined_type_b.B
# - github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGeneric[TConstraint]=github.com/vektra/mockery/v2/pkg/fixtures/constraints.String
# # Replace a generic param with the parent type
# ReplaceGenericSelf:
# config:
# replace-type:
# - github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf[-T]=github.com/vektra/mockery/v2/pkg/fixtures.*ReplaceGenericSelf
# github.com/vektra/mockery/v2/pkg/fixtures/recursive_generation:
# config:
# recursive: True
# all: True
# dir: "{{.InterfaceDir}}"
# filename: "{{.InterfaceName}}_mock.go"
# mockname: "Mock{{.InterfaceName}}"
# outpkg: "{{.PackageName}}"
# inpackage: True
# github.com/vektra/mockery/v2/pkg/fixtures/empty_return:
# config:
# all: True
# dir: "{{.InterfaceDir}}"
# mockname: "{{.InterfaceName}}Mock"
# outpkg: "{{.PackageName}}"
# filename: "mock_{{.InterfaceName}}_test.go"
# inpackage: True
# keeptree: False
# github.com/vektra/mockery/v2/pkg/fixtures/method_args/same_name_arg_and_type:
# config:
# all: True
# dir: "{{.InterfaceDir}}"
# mockname: "{{.InterfaceName}}Mock"
# outpkg: "{{.PackageName}}"
# filename: "mock_{{.InterfaceName}}_test.go"
# inpackage: True
# keeptree: False
# github.com/vektra/mockery/v2/pkg/fixtures/iface_typed_param:
# config: *inpackage_config
# github.com/vektra/mockery/v2/pkg/fixtures/example_project:
# config: *inpackage_config
# github.com/vektra/mockery/v2/pkg/fixtures/index_list_expr:
# config: *inpackage_config
# github.com/vektra/mockery/v2/pkg/fixtures/iface_new_type:
# config: *inpackage_config
# github.com/vektra/mockery/v2/pkg/fixtures/issue845:
# config:
# <<: *inpackage_config
# filename: "mock_{{.MockName}}_test.go"
# interfaces:
# Interface:
# configs:
# - issue-845-fix: False
# mockname: WithoutFix
# - issue-845-fix: True
# mockname: WithFix
# github.com/vektra/mockery/v2/pkg/fixtures/type_alias:
# config:
# all: True
# dir: "{{.InterfaceDir}}"
# filename: "mock_{{.MockName}}_test.go"
# outpkg: "{{.PackageName}}_test"
# inpackage: False
# interfaces:
# Interface1:
# configs:
# - resolve-type-alias: False
# mockname: InterfaceWithUnresolvedAlias
# - resolve-type-alias: True
# mockname: InterfaceWithResolvedAlias
# Interface2:
# configs:
# - resolve-type-alias: False
# mockname: Interface2WithUnresolvedAlias
# - resolve-type-alias: True
# mockname: Interface2WithResolvedAlias
all: True
interfaces:
RequesterArgSameAsNamedImport:
RequesterVariadic:
configs:
- mockname: RequesterVariadicOneArgument
unroll-variadic: False
- mockname: RequesterVariadic
unroll-variadic: True
Expecter:
configs:
- mockname: ExpecterAndRolledVariadic
unroll-variadic: False
- mockname: Expecter
unroll-variadic: True
RequesterReturnElided:
VariadicNoReturnInterface:
config:
unroll-variadic: False
ReplaceGeneric:
ReplaceGenericSelf:
github.com/vektra/mockery/v2/pkg/fixtures/recursive_generation:
config:
recursive: True
all: True
dir: "{{.InterfaceDir}}"
filename: "{{.InterfaceName}}_mock.go"
mockname: "Mock{{.InterfaceName}}"
outpkg: "{{.PackageName}}"
github.com/vektra/mockery/v2/pkg/fixtures/empty_return:
config:
all: True
dir: "{{.InterfaceDir}}"
mockname: "{{.InterfaceName}}Mock"
outpkg: "{{.PackageName}}"
filename: "mock_{{.InterfaceName}}_test.go"
github.com/vektra/mockery/v2/pkg/fixtures/method_args/same_name_arg_and_type:
config:
all: True
dir: "{{.InterfaceDir}}"
mockname: "{{.InterfaceName}}Mock"
outpkg: "{{.PackageName}}"
filename: "mock_{{.InterfaceName}}_test.go"
github.com/vektra/mockery/v2/pkg/fixtures/iface_typed_param:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/example_project:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/index_list_expr:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/iface_new_type:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/issue845:
config:
<<: *inpackage_config
filename: "mock_{{.MockName}}_test.go"
interfaces:
Interface:
configs:
- issue-845-fix: False
mockname: WithoutFix
- issue-845-fix: True
mockname: WithFix
github.com/vektra/mockery/v2/pkg/fixtures/type_alias:
config:
all: True
dir: "{{.InterfaceDir}}"
filename: "mock_{{.MockName}}_test.go"
outpkg: "{{.PackageName}}_test"
17 changes: 17 additions & 0 deletions .mockery_moq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
disable-version-string: True
mockname: "{{.InterfaceName}}Mock"
filename: "moq_test.go"
template: moq
dir: "mocks/moq/{{.PackagePath}}"
formatter: "goimports"

packages:
github.com/vektra/mockery/v2/pkg/fixtures:
config:
include-regex: '.*'
exclude-regex: 'RequesterGenerics|UnsafeInterface|requester_unexported'
outpkg: test
template-data:
with-resets: true
skip-ensure: true
stub-impl: false
17 changes: 14 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ tasks:
- find . -name '*_mock.go' -o -name 'mock_*_test.go' | xargs -r rm
- rm -rf mocks/

mocks.generate:
desc: generate mockery mocks
mocks.generate.mockery:
silent: True
cmds:
- MOCKERY_CONFIG=./.mockery.yaml go run .

mocks.generate.moq:
silent: True
cmds:
- go run .
- MOCKERY_CONFIG=./.mockery_moq.yaml go run .

mocks.generate:
desc: generate mocks
deps:
- mocks.generate.mockery
- mocks.generate.moq

docker:
desc: build the mockery docker image
Expand Down
33 changes: 18 additions & 15 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ import (
)

var (
cfgFile = ""
viperCfg *viper.Viper
cfgFile = ""
)

func init() {
cobra.OnInitialize(func() { initConfig(nil, viperCfg, nil) })
}

func NewRootCmd() *cobra.Command {
viperCfg = viper.NewWithOptions(viper.KeyDelimiter("::"))
func NewRootCmd() (*cobra.Command, error) {
viperCfg, err := getConfig(nil, nil)
if err != nil {
return nil, err
}
cmd := &cobra.Command{
Use: "mockery",
Short: "Generate mock objects for your Golang interfaces",
Expand Down Expand Up @@ -72,7 +70,7 @@ func NewRootCmd() *cobra.Command {
}

cmd.AddCommand(NewShowConfigCmd())
return cmd
return cmd, nil
}

func printStackTrace(e error) {
Expand All @@ -85,16 +83,20 @@ func printStackTrace(e error) {

// Execute executes the cobra CLI workflow
func Execute() {
if err := NewRootCmd().Execute(); err != nil {
cmd, err := NewRootCmd()
if err != nil {
os.Exit(1)
}
if cmd.Execute(); err != nil {
os.Exit(1)
}
}

func initConfig(
func getConfig(
baseSearchPath *pathlib.Path,
viperObj *viper.Viper,
configPath *pathlib.Path,
) *viper.Viper {
) (*viper.Viper, error) {
viperObj := viper.NewWithOptions(viper.KeyDelimiter("::"))
if baseSearchPath == nil {
currentWorkingDir, err := os.Getwd()
if err != nil {
Expand Down Expand Up @@ -140,12 +142,13 @@ func initConfig(
}
if err := viperObj.ReadInConfig(); err != nil {
log, _ := logging.GetLogger("debug")
log.Info().Msg("couldn't read any config file")
log.Err(err).Msg("couldn't read any config file")
return nil, err
}
}

viperObj.Set("config", viperObj.ConfigFileUsed())
return viperObj
return viperObj, nil
}

const regexMetadataChars = "\\.+*?()|[]{}^$"
Expand Down
Loading

0 comments on commit 3740344

Please sign in to comment.