An open API service indexing awesome lists of open source software.

https://github.com/averagebit/mgg

Scans all project files and generates mocks using mockgen mimicking the project structure.
https://github.com/averagebit/mgg

Last synced: 6 months ago
JSON representation

Scans all project files and generates mocks using mockgen mimicking the project structure.

Awesome Lists containing this project

README

          

# mgg

Scans all files in your project. If the path doesn't contain `_test`,
the prefix flag, ends in `.go` and file contains `interface {` it
generates mocks for that interface using
[mockgen](https://github.com/golang/mock).

## Dependencies

- [mockgen](https://github.com/golang/mock)

## Installation

```
go install github.com/averagebit/mgg@latest
```

## Usage

```
# USAGE:
# mgg [OPTIONS]
#
# OPTIONS:
# -h, --help Prints this help message
# -d, --dir Directory to generate mocks in [default: 'mocks']
# -p, --prefix Prefix to use for mock files [default: 'mock_']
# -i, --ignore Paths to ignore when scanning for interfaces [default: ['']]
```

### Example

```
# .
# |--- .git
# |--- README.md
# |--- go.mod
# |--- main.go # has interface
# |--- mocks
# |--- mock_pkg
# |--- mock_logger.go
# |--- mock_pubsub.go
# |--- pkg
# |--- logger.go # has interface
# |--- pubsub.go # has interface

$ mgg --dir=mocks --prefix=mock_ --ignore=main.go,pkg/logger.go
Generated 'mocks/mock_pkg/mock_pubsub.go'
```

## TODO:

- Respect `.gitignore`.
- Support passing flags to `mockgen`.
- Create unit tests.