Skip to content

Commit

Permalink
Merge pull request #672 from hohmannr/feat/interface-name-lower
Browse files Browse the repository at this point in the history
Feat/interface name lower
  • Loading branch information
LandonTClipp authored Jul 11, 2023
2 parents b5592d6 + 6e6efc2 commit 8c06cfc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Variables that are marked as being templated are capable of using mockery-provid
| InterfaceNameCamel | Converts a string `interface_name` to `InterfaceName` |
| InterfaceNameLowerCamel | Converts `InterfaceName` to `interfaceName` |
| InterfaceNameSnake | Converts `InterfaceName` to `interface_name` |
| InterfaceNameLower | Converts `InterfaceName` to `interfacename` |
| Mock | A string that is `Mock` if the interface is exported, or `mock` if it is not exported. Useful when setting the name of your mock to something like: <br>`#!yaml mockname: "{{.Mock}}{{.InterfaceName}}"`<br> This way, the mock name will retain the exported-ness of the original interface.
| MockName | The name of the mock that will be generated. Note that this is simply the `mockname` configuration variable |
| PackageName | The name of the package from the original interface |
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func (c *Config) subPackages(
return nil
})
if walkErr != nil {
return nil, fmt.Errorf("error occured during filesystem walk: %w", walkErr)
return nil, fmt.Errorf("error occurred during filesystem walk: %w", walkErr)
}

// Parse the subdirectories we found into their respective fully qualified
Expand Down
6 changes: 4 additions & 2 deletions pkg/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/vektra/mockery/v2/pkg/stackerr"
)

var ErrInfiniteLoop = fmt.Errorf("infintie loop in template variables detected")
var ErrInfiniteLoop = fmt.Errorf("infinite loop in template variables detected")

// Functions available in the template for manipulating
//
Expand Down Expand Up @@ -206,6 +206,7 @@ func parseConfigTemplates(ctx context.Context, c *config.Config, iface *Interfac
InterfaceNameCamel string
InterfaceNameLowerCamel string
InterfaceNameSnake string
InterfaceNameLower string
Mock string
MockName string
PackageName string
Expand All @@ -217,6 +218,7 @@ func parseConfigTemplates(ctx context.Context, c *config.Config, iface *Interfac
InterfaceNameCamel: strcase.ToCamel(iface.Name),
InterfaceNameLowerCamel: strcase.ToLowerCamel(iface.Name),
InterfaceNameSnake: strcase.ToSnake(iface.Name),
InterfaceNameLower: strings.ToLower(iface.Name),
Mock: mock,
MockName: c.MockName,
PackageName: iface.Pkg.Name(),
Expand All @@ -236,7 +238,7 @@ func parseConfigTemplates(ctx context.Context, c *config.Config, iface *Interfac
changesMade := true
for changesMade {
if numIterations >= 20 {
msg := "infintie loop in template variables detected"
msg := "infinite loop in template variables detected"
log.Error().Msg(msg)
for key, val := range templateMap {
l := log.With().Str("variable-name", key).Str("variable-value", *val).Logger()
Expand Down
4 changes: 2 additions & 2 deletions pkg/outputter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Test_parseConfigTemplates(t *testing.T) {
args: args{
c: &config.Config{
Dir: "{{.InterfaceDir}}/{{.PackagePath}}",
FileName: "{{.InterfaceName}}_{{.InterfaceNameCamel}}_{{.InterfaceNameSnake}}.go",
FileName: "{{.InterfaceName}}_{{.InterfaceNameCamel}}_{{.InterfaceNameSnake}}_{{.InterfaceNameLower}}.go",
MockName: "{{.InterfaceNameLowerCamel}}",
Outpkg: "{{.PackageName}}",
},
Expand All @@ -110,7 +110,7 @@ func Test_parseConfigTemplates(t *testing.T) {
pkg: mockPkg,
want: &config.Config{
Dir: "path/to/github.com/user/project/package",
FileName: "FooBar_FooBar_foo_bar.go",
FileName: "FooBar_FooBar_foo_bar_foobar.go",
MockName: "fooBar",
Outpkg: "packageName",
},
Expand Down

0 comments on commit 8c06cfc

Please sign in to comment.