Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #528

Merged
merged 1 commit into from Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 43 additions & 32 deletions README.md
Expand Up @@ -14,6 +14,9 @@ Table of Contents
* [Docker](#docker)
* [Homebrew](#homebrew)
* [go install](#go-install)
- [Configuration](#configuration)
* [Example](#example)
* [Config Search Path](#config-search-path)
- [Examples](#examples)
+ [Simplest case](#simplest-case)
+ [Function type case](#function-type-case)
Expand All @@ -25,10 +28,12 @@ Table of Contents
- [Expecter Interfaces](#expecter-interfaces)
- [Mock constructors](#mock-constructors)
- [Extended Flag Descriptions](#extended-flag-descriptions)
- [Mocking interfaces in `main`](#mocking-interfaces-in-main)
- [Configuration](#configuration)
* [Example](#example)
- [Mocking interfaces in `main`](#mocking-interfaces-in--main-)
- [Semantic Versioning](#semantic-versioning)
- [Development Efforts](#development-efforts)
* [v1](#v1)
* [v2](#v2)
* [v3](#v3)
- [Stargazers](#stargazers)


Expand Down Expand Up @@ -64,6 +69,41 @@ Alternatively, you can use the go install method to compile the project using yo

go install github.com/vektra/mockery/v2@latest

Configuration
--------------

mockery uses [spf13/viper](https://github.com/spf13/viper) under the hood for its configuration parsing. It is bound to three different configuration sources, in order of decreasing precedence:

1. Command line
2. Environment variables
3. Configuration file

### Example

$ export MOCKERY_STRUCTNAME=config_from_env
$ echo $MOCKERY_STRUCTNAME
config_from_env
$ grep structname .mockery.yaml
structname: config_from_file
$ ./mockery showconfig --structname config_from_cli | grep structname
Using config file: /home/ltclipp/git/vektra/mockery/.mockery.yaml
structname: config_from_cli
$ ./mockery showconfig | grep structname
Using config file: /home/ltclipp/git/vektra/mockery/.mockery.yaml
structname: config_from_env
$ unset MOCKERY_STRUCTNAME
$ ./mockery showconfig | grep structname
Using config file: /home/ltclipp/git/vektra/mockery/.mockery.yaml
structname: config_from_file

By default, it searches the current working directory for a file named `.mockery.[extension]` where [extension] is any of the [recognized extensions](https://pkg.go.dev/github.com/spf13/viper@v1.7.0?tab=doc#pkg-variables).

### Config Search Path

New in [v2.16.0](https://github.com/vektra/mockery/pull/527)

Mockery will iteratively search every directory from the current working directory up to the root path for a `.mockery.yaml` file, if one is not explicitly provided.

Examples
--------

Expand Down Expand Up @@ -376,35 +416,6 @@ Mocking interfaces in `main`
When your interfaces are in the main package, you should supply the `--inpackage` flag.
This will generate mocks in the same package as the target code, avoiding import issues.

Configuration
--------------

mockery uses [spf13/viper](https://github.com/spf13/viper) under the hood for its configuration parsing. It is bound to three different configuration sources, in order of decreasing precedence:

1. Command line
2. Environment variables
3. Configuration file

### Example

$ export MOCKERY_STRUCTNAME=config_from_env
$ echo $MOCKERY_STRUCTNAME
config_from_env
$ grep structname .mockery.yaml
structname: config_from_file
$ ./mockery showconfig --structname config_from_cli | grep structname
Using config file: /home/ltclipp/git/vektra/mockery/.mockery.yaml
structname: config_from_cli
$ ./mockery showconfig | grep structname
Using config file: /home/ltclipp/git/vektra/mockery/.mockery.yaml
structname: config_from_env
$ unset MOCKERY_STRUCTNAME
$ ./mockery showconfig | grep structname
Using config file: /home/ltclipp/git/vektra/mockery/.mockery.yaml
structname: config_from_file

By default, it searches the current working directory for a file named `.mockery.[extension]` where [extension] is any of the [recognized extensions](https://pkg.go.dev/github.com/spf13/viper@v1.7.0?tab=doc#pkg-variables).

Semantic Versioning
-------------------

Expand Down