Skip to content

Commit

Permalink
Merge pull request #544 from LandonTClipp/mkdocs
Browse files Browse the repository at this point in the history
Add more mkdocs documentation, examples etc
  • Loading branch information
LandonTClipp authored Feb 10, 2023
2 parents 93af858 + b663aee commit 94da44d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ mockery.prof
dist
.idea
docs/ve
ve
90 changes: 90 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Getting Started
================

Installation
-------------

### go install

Supported, but not recommended: [see wiki page](https://github.com/vektra/mockery/wiki/Installation-Methods#go-install) and [related discussions](https://github.com/vektra/mockery/pull/456).

Alternatively, you can use the go install method to compile the project using your local environment:

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

### GitHub Release

Visit the [releases page](https://github.com/vektra/mockery/releases) to download one of the pre-built binaries for your platform.

### Docker

Use the [Docker image](https://hub.docker.com/r/vektra/mockery)

docker pull vektra/mockery

Generate all the mocks for your project:

docker run -v "$PWD":/src -w /src vektra/mockery --all

### Homebrew

Install through [brew](https://brew.sh/)

brew install mockery
brew upgrade mockery

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

Copy the recommended basic configuration to a file called `.mockery.yaml` at the top-level of your repo:

```yaml
all: True
keeptree: True
```
mockery will search upwards from your current-working-directory up to the root path, so the same configuration should be able to follow you within your project.
Run mockery
------------
### For all interfaces in project
```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
```

### Using `go generate`

`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 --all=False
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
```

Note that mockery running in `go generate` will still ingest configuration from your top-level `.mockery.yaml` file, so you may have to enable/disable certain configuration parameters from the command line to prevent collisions.
3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mockery
=========
========

Welcome to mockery! This is the initial scaffolding for the documentation.
22 changes: 20 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
site_name: mockery
theme:
name: material


palette:
# Palette toggle for light mode
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
# Palette toggle for dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode
features:
- content.code.copy
markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
auto_title: true
- pymdownx.superfences
39 changes: 39 additions & 0 deletions mocks/pkg/fixtures/example_project/GoGenerateExample.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/fixtures/example_project/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package example_project

//go:generate mockery --name GoGenerateExample --all=False
type GoGenerateExample interface {
Foo(s string) error
}

0 comments on commit 94da44d

Please sign in to comment.