Skip to content

Commit 3ed8ae7

Browse files
authored
Merge pull request #1135 from LandonTClipp/fix_interface_dir_relative
Fix breaking change with InterfaceDirRelative
2 parents e7de6fc + cff9a51 commit 3ed8ae7

File tree

6 files changed

+95
-11
lines changed

6 files changed

+95
-11
lines changed

.mockery_testify.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,13 @@ packages:
142142
github.com/vektra/mockery/v3/internal/fixtures/constraint_ifaces:
143143
github.com/vektra/mockery/v3/internal/fixtures/interface_dir_relative:
144144
config:
145-
dir: '{{.InterfaceDir}}/{{ replaceAll "internal/" "" (index (splitAfterN "/" 2 .InterfaceDirRelative) 0) }}/mocks/{{index (splitAfterN "/" 2 .InterfaceDirRelative) 1}}'
146-
filename: "mocks_{{.InterfaceName}}.go"
145+
filename: mocks.go
146+
interfaces:
147+
Foo:
148+
configs:
149+
# This first option simply asserts that InterfaceDirRelative is an actual path. https://github.com/vektra/mockery/issues/1133
150+
- dir: '{{.InterfaceDir}}/{{ replaceAll "internal/" "" (index (splitAfterN "/" 2 .InterfaceDirRelative) 0) }}/mocks/{{index (splitAfterN "/" 2 .InterfaceDirRelative) 1}}'
151+
# The second option asserts that the value itself is sane. https://github.com/vektra/mockery/issues/1133#issuecomment-3758283921
152+
# This mock will be explicitly tested against so that we can assert in tests that the value
153+
# does not encounter breaking changes.
154+
- dir: '{{.InterfaceDir}}/{{.InterfaceDirRelative}}'

config/config.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,7 @@ func (c *Config) ParseTemplates(
653653
workingDir = filepath.ToSlash(workingDir)
654654
ifaceFilePath = filepath.ToSlash(filepath.Clean(ifaceFilePath))
655655
interfaceDirPath := filepath.ToSlash(filepath.Dir(ifaceFilePath))
656-
configPathAbs, err := filepath.Abs(*c.ConfigFile)
657-
if err != nil {
658-
return fmt.Errorf("getting absolute path of config file: %w", err)
659-
}
660-
configPathDir := filepath.ToSlash(filepath.Dir(configPathAbs))
661-
662-
interfaceDirRelativePath, err := filepath.Rel(filepath.FromSlash(configPathDir), filepath.FromSlash(interfaceDirPath))
656+
interfaceDirRelativePath, err := filepath.Rel(filepath.FromSlash(workingDir), filepath.FromSlash(interfaceDirPath))
663657

664658
var interfaceDirRelative string
665659

internal/fixtures/interface_dir_relative/interface_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package interfacedirrelative
33
import (
44
"testing"
55

6-
mocks "github.com/vektra/mockery/v3/internal/fixtures/interface_dir_relative/mocks/fixtures/interface_dir_relative"
6+
mocks "github.com/vektra/mockery/v3/internal/fixtures/interface_dir_relative/internal/fixtures/interface_dir_relative"
77
)
88

99
func TestFoo(t *testing.T) {

internal/fixtures/interface_dir_relative/mocks/fixtures/interface_dir_relative/mocks_Foo.go renamed to internal/fixtures/interface_dir_relative/internal/fixtures/interface_dir_relative/mocks.go

File renamed without changes.

internal/fixtures/interface_dir_relative/mocks/fixtures/interface_dir_relative/mocks.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mockery-tools.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=v3.6.2
1+
VERSION=v3.6.3

0 commit comments

Comments
 (0)