-
Notifications
You must be signed in to change notification settings - Fork 420
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 #668 from LandonTClipp/deprecation
Add deprecation notice for old config style
- Loading branch information
Showing
8 changed files
with
345 additions
and
259 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
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,47 +1,30 @@ | ||
Running | ||
======== | ||
|
||
Using `go generate` <small>recommended</small> | ||
-------------------- | ||
|
||
`go generate` is often preferred as it give you more targeted generation of specific interfaces. Use `generate` as a directive above the interface you want to generate a mock for. | ||
|
||
``` golang | ||
package example_project | ||
|
||
//go:generate mockery --name Root | ||
type Root interface { | ||
Foobar(s string) error | ||
} | ||
``` | ||
|
||
Then simply: | ||
|
||
``` bash | ||
$ go generate | ||
09 Feb 23 22:55 CST INF Starting mockery dry-run=false version=v2.18.0 | ||
09 Feb 23 22:55 CST INF Using config: /Users/landonclipp/git/LandonTClipp/mockery/.mockery.yaml dry-run=false version=v2.18.0 | ||
09 Feb 23 22:55 CST INF Walking dry-run=false version=v2.18.0 | ||
09 Feb 23 22:55 CST INF Generating mock dry-run=false interface=Root qualified-name=github.com/vektra/mockery/v2/pkg/fixtures/example_project version=v2.18.0 | ||
If your `.mockery.yaml` file has been populated with the packages and interfaces you want mocked, mockery can be run with no arguments. Take for example how the mockery project itself is configured: | ||
|
||
```yaml | ||
quiet: False | ||
keeptree: True | ||
disable-version-string: True | ||
with-expecter: True | ||
mockname: "{{.InterfaceName}}" | ||
filename: "{{.MockName}}.go" | ||
outpkg: mocks | ||
packages: | ||
github.com/vektra/mockery/v2/pkg: | ||
interfaces: | ||
TypesPackage: | ||
# Lots more config... | ||
``` | ||
|
||
For all interfaces in project | ||
------------------------------ | ||
|
||
If you provide `all: True`, you can generate mocks for the entire project. This is not recommended for larger projects as it can take a large amount of time parsing packages to generate mocks that you might never use. | ||
From anywhere within your repo, you can simply call `mockery` once and it will find your config either by respecting the `#!yaml config` path you gave it, or by searching upwards from the current working directory. | ||
|
||
```bash | ||
$ mockery | ||
09 Feb 23 22:47 CST INF Starting mockery dry-run=false version=v2.18.0 | ||
09 Feb 23 22:47 CST INF Using config: /Users/landonclipp/git/LandonTClipp/mockery/.mockery.yaml dry-run=false version=v2.18.0 | ||
09 Feb 23 22:47 CST INF Walking dry-run=false version=v2.18.0 | ||
09 Feb 23 22:47 CST INF Generating mock dry-run=false interface=A qualified-name=github.com/vektra/mockery/v2/pkg/fixtures version=v2.18.0 | ||
mockery | ||
08 Jul 23 01:40 EDT INF Starting mockery dry-run=false version=v2.31.0 | ||
08 Jul 23 01:40 EDT INF Using config: /Users/landonclipp/git/LandonTClipp/mockery/.mockery.yaml dry-run=false version=v2.31.0 | ||
``` | ||
|
||
!!! note | ||
|
||
Note that in some cases, using `//go:generate` may turn out to be slower than running for entire packages. `go:generate` calls mockery once for each `generate` directive, which means that mockery may need to parse the package multiple times, which is wasteful. Good judgement is recommended when determining the best option for your own project. | ||
|
||
!!! note | ||
|
||
For mockery to correctly generate mocks, the command has to be run on a module (i.e. your project has to have a go.mod file) | ||
!!! question "Command line arguments" | ||
It is valid to specify arguments from the command line. The configuration precedence is specified in the [Configuration](configuration.md#merging-precedence) docs. |
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,62 @@ | ||
package logging | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_getMinorSemver(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg string | ||
want string | ||
}{ | ||
{ | ||
name: "default semver", | ||
arg: "v0.0.0-dev", | ||
want: "v0.0", | ||
}, | ||
{ | ||
name: "example semver", | ||
arg: "v2.0.1", | ||
want: "v2.0", | ||
}, | ||
{ | ||
name: "example semver with alpha notation", | ||
arg: "v3.0.0-alpha.0", | ||
want: "v3.0", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := getMinorSemver(tt.arg); got != tt.want { | ||
t.Errorf("getMinorSemver() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDocsURL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg string | ||
want string | ||
}{ | ||
{ | ||
name: "url with no leading slash", | ||
arg: "features", | ||
want: "https://vektra.github.io/mockery/v0.0/features", | ||
}, | ||
{ | ||
name: "url with leading slash", | ||
arg: "/features", | ||
want: "https://vektra.github.io/mockery/v0.0/features", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := DocsURL(tt.arg); got != tt.want { | ||
t.Errorf("DocsURL() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |