Skip to content

Commit 5f1374c

Browse files
committed
Fix breaking change with InterfaceDirRelative
An attempt to fix a breaking change between v2 and v3 with InterfaceDirRelative inadvertently caused another breaking change with existing v3 users. Tests have been added that assert both cases are sane and work properly. Related to #1133.
1 parent 6e6205d commit 5f1374c

File tree

5 files changed

+94
-10
lines changed

5 files changed

+94
-10
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.

0 commit comments

Comments
 (0)