Skip to content

Commit

Permalink
Migrate github.com/golang/mock to github.com/uber-go/mock
Browse files Browse the repository at this point in the history
  • Loading branch information
manjari25 committed Sep 25, 2023
1 parent 7309aba commit c1654ab
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 82 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ go_deps.module(
use_repo(
go_deps,
"com_github_gogo_protobuf",
"com_github_golang_mock",
"com_github_golang_protobuf",
"org_golang_google_genproto",
"org_golang_google_grpc",
"org_golang_google_protobuf",
"org_golang_x_net",
"org_uber_go_mock",
)
2 changes: 1 addition & 1 deletion docs/go/core/bzlmod.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"com_github_gogo_protobuf",
"com_github_golang_mock",
"com_github_golang_protobuf",
"org_golang_x_net",
"org_uber_go_mock",
)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/go/extras/extras.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
[gazelle rule]: https://github.com/bazelbuild/bazel-gazelle#bazel-rule
[golang/mock]: https://github.com/golang/mock
[uber-go/mock]: https://github.com/uber-go/mock
[core go rules]: /docs/go/core/rules.md
# Extra rules
Expand All @@ -14,7 +14,7 @@ to make life a little easier.
## Additional resources
- [gazelle rule]
- [golang/mock]
- [uber-go/mock]
- [core go rules]
------------------------------------------------------------------------
Expand Down
18 changes: 9 additions & 9 deletions docs/go/extras/extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


[gazelle rule]: https://github.com/bazelbuild/bazel-gazelle#bazel-rule
[golang/mock]: https://github.com/golang/mock
[uber-go/mock]: https://github.com/uber-go/mock
[core go rules]: /docs/go/core/rules.md

# Extra rules
Expand All @@ -16,7 +16,7 @@ to make life a little easier.

## Additional resources
- [gazelle rule]
- [golang/mock]
- [uber-go/mock]
- [core go rules]

------------------------------------------------------------------------
Expand All @@ -37,7 +37,7 @@ gomock(<a href="#gomock-name">name</a>, <a href="#gomock-library">library</a>, <
<a href="#gomock-imports">imports</a>, <a href="#gomock-copyright_file">copyright_file</a>, <a href="#gomock-mock_names">mock_names</a>, <a href="#gomock-kwargs">kwargs</a>)
</pre>

Calls [mockgen](https://github.com/golang/mock) to generates a Go file containing mocks from the given library.
Calls [mockgen](https://github.com/uber-go/mock) to generates a Go file containing mocks from the given library.

If `source` is given, the mocks are generated in source mode; otherwise in reflective mode.

Expand All @@ -52,13 +52,13 @@ If `source` is given, the mocks are generated in source mode; otherwise in refle
| <a id="gomock-out"></a>out | the output Go file name. | none |
| <a id="gomock-source"></a>source | a Go file in the given <code>library</code>. If this is given, <code>gomock</code> will call mockgen in source mode to mock all interfaces in the file. | <code>None</code> |
| <a id="gomock-interfaces"></a>interfaces | a list of interfaces in the given <code>library</code> to be mocked in reflective mode. | <code>[]</code> |
| <a id="gomock-package"></a>package | the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/golang/mock#flags) for more information. | <code>""</code> |
| <a id="gomock-self_package"></a>self_package | the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See [mockgen's -self_package](https://github.com/golang/mock#flags) for more information. | <code>""</code> |
| <a id="gomock-aux_files"></a>aux_files | a map from source files to their package path. This only needed when <code>source</code> is provided. See [mockgen's -aux_files](https://github.com/golang/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-package"></a>package | the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/uber-go/mock#flags) for more information. | <code>""</code> |
| <a id="gomock-self_package"></a>self_package | the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See [mockgen's -self_package](https://github.com/uber-go/mock#flags) for more information. | <code>""</code> |
| <a id="gomock-aux_files"></a>aux_files | a map from source files to their package path. This only needed when <code>source</code> is provided. See [mockgen's -aux_files](https://github.com/uber-go/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-mockgen_tool"></a>mockgen_tool | the mockgen tool to run. | <code>Label("//extras/gomock:mockgen")</code> |
| <a id="gomock-imports"></a>imports | dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/golang/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-copyright_file"></a>copyright_file | optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/golang/mock#flags) for more information. | <code>None</code> |
| <a id="gomock-mock_names"></a>mock_names | dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/golang/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-imports"></a>imports | dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/uber-go/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-copyright_file"></a>copyright_file | optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/uber-go/mock#flags) for more information. | <code>None</code> |
| <a id="gomock-mock_names"></a>mock_names | dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/uber-go/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-kwargs"></a>kwargs | <p align="center"> - </p> | none |


14 changes: 7 additions & 7 deletions extras/gomock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ _gomock_source = rule(
)

def gomock(name, library, out, source = None, interfaces = [], package = "", self_package = "", aux_files = {}, mockgen_tool = _MOCKGEN_TOOL, imports = {}, copyright_file = None, mock_names = {}, **kwargs):
"""Calls [mockgen](https://github.com/golang/mock) to generates a Go file containing mocks from the given library.
"""Calls [mockgen](https://github.com/uber-go/mock) to generates a Go file containing mocks from the given library.
If `source` is given, the mocks are generated in source mode; otherwise in reflective mode.
Expand All @@ -161,13 +161,13 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel
out: the output Go file name.
source: a Go file in the given `library`. If this is given, `gomock` will call mockgen in source mode to mock all interfaces in the file.
interfaces: a list of interfaces in the given `library` to be mocked in reflective mode.
package: the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/golang/mock#flags) for more information.
self_package: the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See [mockgen's -self_package](https://github.com/golang/mock#flags) for more information.
aux_files: a map from source files to their package path. This only needed when `source` is provided. See [mockgen's -aux_files](https://github.com/golang/mock#flags) for more information.
package: the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/uber-go/mock#flags) for more information.
self_package: the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See [mockgen's -self_package](https://github.com/uber-go/mock#flags) for more information.
aux_files: a map from source files to their package path. This only needed when `source` is provided. See [mockgen's -aux_files](https://github.com/uber-go/mock#flags) for more information.
mockgen_tool: the mockgen tool to run.
imports: dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/golang/mock#flags) for more information.
copyright_file: optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/golang/mock#flags) for more information.
mock_names: dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/golang/mock#flags) for more information.
imports: dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/uber-go/mock#flags) for more information.
copyright_file: optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/uber-go/mock#flags) for more information.
mock_names: dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/uber-go/mock#flags) for more information.
kwargs: common attributes](https://bazel.build/reference/be/common-definitions#common-attributes) to all Bazel rules.
"""
if source:
Expand Down
6 changes: 3 additions & 3 deletions extras/gomock/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
alias(
name = "gomock",
actual = "@com_github_golang_mock//gomock",
actual = "@org_uber_go_mock//gomock",
visibility = ["//visibility:public"],
)

alias(
name = "mockgen",
actual = "@com_github_golang_mock//mockgen",
actual = "@org_uber_go_mock//mockgen",
visibility = ["//visibility:public"],
)

alias(
name = "mockgen_model",
actual = "@com_github_golang_mock//mockgen/model",
actual = "@org_uber_go_mock//mockgen/model",
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/bazelbuild/rules_go
go 1.18

require (
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
google.golang.org/protobuf v1.28.0
go.uber.org/mock v0.3.0
)

require (
Expand Down
16 changes: 7 additions & 9 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,20 @@ def go_rules_dependencies(force = False):
patch_args = ["-p1"],
)

# releaser:upgrade-dep golang mock
# go.uber.org/mock dependency
_maybe(
http_archive,
name = "com_github_golang_mock",
# v1.7.0-rc.1, latest as of 2023-06-08
name = "org_uber_go_mock",
# 0.3.0 latest as of 2023-09-20
urls = [
"https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
"https://github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
"https://github.com/uber-go/mock/archive/refs/tags/v0.3.0.zip",
],
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/mock -go_naming_convention import_alias
Label("//third_party:com_github_golang_mock-gazelle.patch"),
Label("//third_party:org_uber_go_mock-gazelle.patch"),
],
patch_args = ["-p1"],
sha256 = "5359c78b0c1649cf7beb3b48ff8b1d1aaf0243b22ea4789aba94805280075d8e",
strip_prefix = "mock-1.7.0-rc.1",
sha256 = "d20bfd623dfb4e2fa1cdac617cde142f72f53285894c137c7911fc1afce0de7c",
strip_prefix = "mock-0.3.0",
)

# This may be overridden by go_register_toolchains, but it's not mandatory
Expand Down
2 changes: 1 addition & 1 deletion tests/extras/gomock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ go_test(
"client_test.go",
],
embed = [":client"],
deps = ["@com_github_golang_mock//gomock"],
deps = ["@org_uber_go_mock//gomock"],
)

0 comments on commit c1654ab

Please sign in to comment.