Skip to content

Commit

Permalink
Add InterfaceDir template variable
Browse files Browse the repository at this point in the history
This fixes #574
  • Loading branch information
LandonTClipp committed Mar 9, 2023
1 parent e478c25 commit 61d7db1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,13 @@ func outputFilePath(

// The fields available to the template strings
data := struct {
InterfaceDir string
InterfaceName string
PackageName string
PackagePath string
MockName string
}{
InterfaceDir: filepath.Dir(iface.FileName),
InterfaceName: iface.Name,
PackageName: iface.Pkg.Name(),
PackagePath: iface.Pkg.Path(),
Expand Down
19 changes: 17 additions & 2 deletions pkg/outputter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func Test_outputFilePath(t *testing.T) {
packageName string
packagePath string
interfaceName string
fileName string
fileNameTemplate string
dirTemplate string
mockName string
Expand Down Expand Up @@ -128,6 +129,19 @@ func Test_outputFilePath(t *testing.T) {
},
want: pathlib.NewPath("github.com/vektra/mockery/MockFoo_pkg_Foo.go"),
},
{
name: "mock next to original interface",
params: parameters{
packageName: "pkg",
packagePath: "github.com/vektra/mockery/pkg/internal",
interfaceName: "Foo",
fileName: "pkg/internal/foo.go",
dirTemplate: "{{.InterfaceDir}}",
fileNameTemplate: "mock_{{.InterfaceName}}.go",
mockName: "MockFoo",
},
want: pathlib.NewPath("pkg/internal/mock_Foo.go"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -136,8 +150,9 @@ func Test_outputFilePath(t *testing.T) {
mockPackage.EXPECT().Path().Return(tt.params.packagePath)

iface := &Interface{
Name: tt.params.interfaceName,
Pkg: mockPackage,
Name: tt.params.interfaceName,
Pkg: mockPackage,
FileName: tt.params.fileName,
}

got, err := outputFilePath(
Expand Down

0 comments on commit 61d7db1

Please sign in to comment.