You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
* header.yml is missing so removing ineffective go-license
* Remove unneeded source constants
* Remove unneeded source versions
* Use go generate commands to generate mocks
* Remove the need to install mockgen in the script
* Add mock-up-to-date step to test CI workflow
* Remove all mocks before generating them in CI
* Add generate command for non-tracked mock
(Note using source mode was compulsory due to CGO)
* Use bash shell for mock check step
* Remove script mock.gen.sh
* docs(contributing): add mocks section
* mockgen version used is the one defined in go.mod
- requires a `tools.go` blank importing golang.org/x/tools/imports in order to have the `golang.org/x/tools` dependency satisfied for mockgen v0.4
- less future deltas when upgrading mockgen
* ci: use more precise go generate regex
* Add `git add --intent-to-add --all` to detect untracked files
* Add copyright notices
Copy file name to clipboardExpand all lines: .github/CONTRIBUTING.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,3 +33,36 @@ Please make sure your contributions adhere to our coding guidelines:
33
33
Before you submit a feature request, please check and make sure that it isn't
34
34
possible through some other means.
35
35
36
+
## Mocks
37
+
38
+
Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/mockgen) and `//go:generate` commands in the code.
39
+
40
+
* To **re-generate all mocks**, use the command below from the root of the project:
41
+
42
+
```sh
43
+
go generate -run "go.uber.org/mock/mockgen" ./...
44
+
```
45
+
46
+
* To **add** an interface that needs a corresponding mock generated:
47
+
*if the file `mocks_generate_test.go` exists in the package where the interface is located, either:
48
+
* modify its `//go:generate go run go.uber.org/mock/mockgen` to generate a mock for your interface (preferred); or
49
+
* add another `//go:generate go run go.uber.org/mock/mockgen` to generate a mock for your interface according to specific mock generation settings
50
+
*if the file `mocks_generate_test.go` does not exist in the package where the interface is located, create it with content (adapt as needed):
51
+
52
+
```go
53
+
// Copyright (C) 2025-2025, Ava Labs, Inc. All rights reserved.
54
+
// See the file LICENSE for licensing terms.
55
+
56
+
package mypackage
57
+
58
+
//go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mocks_test.go . YourInterface
59
+
```
60
+
61
+
Notes:
62
+
1. Ideally generate all mocks to `mocks_test.go`for the package you need to use the mocks for and do not export mocks to other packages. This reduces package dependencies, reduces production code pollution and forces to have locally defined narrow interfaces.
63
+
1. Prefer using reflect mode to generate mocks than source mode, unless you need a mock for an unexported interface, which should be rare.
64
+
* To **remove** an interface from having a corresponding mock generated:
65
+
1. Edit the `mocks_generate_test.go` file in the directory where the interface is defined
66
+
1. If the `//go:generate` mockgen command line:
67
+
* generates a mock file for multiple interfaces, remove your interface from the line
68
+
* generates a mock file only for the interface, remove the entire line. If the file is empty, remove `mocks_generate_test.go` as well.
0 commit comments