forked from ebhomengo/niki
17 lines
509 B
Markdown
17 lines
509 B
Markdown
## Mocking interfaces in unit tests
|
|
1- add a //go:generate directive above the interface:
|
|
```go
|
|
//go:generate mockery --name Repository
|
|
type Repository interface {
|
|
AdminExistByPhoneNumber(ctx context.Context, phoneNumber string) (bool, error)
|
|
AdminExistByEmail(ctx context.Context, email string) (bool, error)
|
|
}
|
|
```
|
|
2- run go generate to create the mock files:
|
|
```bash
|
|
go generate ./...
|
|
```
|
|
3- use the generated mock types in your tests.
|
|
|
|
for more information visit:
|
|
https://vektra.github.io/mockery/latest/ |