-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #846 from LandonTClipp/LandonTClipp/issue_845
Fix `outpkg` not being respected when `inpackage: True`.
- Loading branch information
Showing
13 changed files
with
302 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Deprecations | ||
============= | ||
|
||
`packages` | ||
---------- | ||
|
||
The [`packages`](features.md#packages-configuration) feature will be the only way to configure mockery in the future. | ||
|
||
`issue-845-fix` | ||
--------------- | ||
|
||
This parameter fixes a somewhat uninteresting, but important issue found in [#845](https://github.com/vektra/mockery/issues/845). | ||
In short, mockery ignored the `#!yaml outpkg:` parameter if `#!yaml inpackage:` was set to `#!yaml True`. This prevents users | ||
from being able to set alternate package names for their mocks that are generated in the same directory | ||
as the mocked interface. For example, it's legal Go to append `_test` to the mock package name | ||
if the file is appended with `_test.go` as well. This parameter will be permanently | ||
enabled in mockery v3. | ||
|
||
As an example, if you had configuration that looked like this: | ||
|
||
```yaml | ||
all: True | ||
dir: "{{.InterfaceDir}}" | ||
mockname: "{{.InterfaceName}}Mock" | ||
outpkg: "{{.PackageName}}_test" | ||
filename: "mock_{{.InterfaceName}}_test.go" | ||
inpackage: True | ||
``` | ||
The `#!yaml outpkg` parameter would not be respected and instead would be forced to take on the value of `#!yaml "{{.PackageName}}"`. | ||
To remove the warning, you must set: | ||
|
||
```yaml | ||
issue-845-fix: True | ||
``` | ||
|
||
After this is done, mocks generated in the old scheme will properly respect the `#!yaml outpkg:` parameter previously set | ||
if being generated with `#!yaml inpackage: True`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package issue845 | ||
|
||
type Interface interface { | ||
Foo() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package issue845 | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/chigopher/pathlib" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFix(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
filepath string | ||
expectedPackage string | ||
}{ | ||
{ | ||
name: "with fix", | ||
filepath: "./mock_WithFix_test.go", | ||
expectedPackage: "package issue845_test", | ||
}, | ||
{ | ||
name: "without fix", | ||
filepath: "./mock_WithoutFix_test.go", | ||
expectedPackage: "package issue845", | ||
}, | ||
} { | ||
t.Run( | ||
tt.name, | ||
func(t *testing.T) { | ||
path := pathlib.NewPath(tt.filepath) | ||
bytes, err := path.ReadFile() | ||
require.NoError(t, err) | ||
fileString := string(bytes) | ||
assert.True(t, strings.Contains(fileString, tt.expectedPackage)) | ||
}, | ||
) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.