Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Replace github.com/golang/mock with go.uber.org/mock
Browse files Browse the repository at this point in the history
`github.com/golang/mock` is no maintained and `go.uber.org/mock` is the
recommmended fork alternative.

> Update, June 2023: This repo and tool are no longer maintained. Please
> see go.uber.org/mock for a maintained fork instead.

I deliberately picked an older version (v0.1.0) because it mirrors
`github.com/golang/mock` and can be migrated to as-is.

Fixes #62
  • Loading branch information
lithammer committed Sep 27, 2023
1 parent 4f2ee84 commit 73ec599
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ gomock for Bazel
================

This skylark code allows you to generate code with `mockgen` (from
[`golang/mock`](https://github.com/golang/mock)) and use that code as a dependency in
[`go.uber.org/mock`](https://github.com/uber-go/mock) and use that code as a dependency in
your bazel projects. It handles all the `GOPATH` stuff for you.


Setup
---

`bazel_gomock` requires a `rules_go` external to be set up in your `WORKSPACE`
as well as a `go_repository` call for `com_github_golang_mock`.
as well as a `go_repository` call for `org_uber_go_mock`.

Then in your `WORKSPACE`, add

Expand All @@ -27,14 +27,14 @@ http_archive(
)
```

An example of a `com_github_golang_mock` you'd need:
An example of a `org_uber_go_mock` you'd need:

```python
go_repository(
name = "com_github_golang_mock",
importpath = "github.com/golang/mock",
sum = "h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=",
version = "v1.4.4",
name = "org_uber_go_mock",
importpath = "go.uber.org/mock",
sum = "h1:NEVjcPIj/L96qilPi+2M5l9zUkQksRaqNKphz3pStHI=",
version = "v0.1.0",
)
```

Expand Down Expand Up @@ -95,7 +95,7 @@ Also, `gazelle` will remove the generated source file from a `go_test` target's
As a likely unused feature, you can pass in an alternative
external for where to find the `mockgen` tool target using the `mockgen_tool`
parameter. The only rule for the target is that must be a binary. The current
default is `"@com_github_golang_mock//mockgen"`.
default is `"@org_uber_go_mock//mockgen"`.

If you try to use `gomock` on a `go_library` that is in the package `main` (and so
probably being immediately used as an `embed` target for a `go_binary`), you'll
Expand Down
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()

go_repository(
name = "com_github_golang_mock",
importpath = "github.com/golang/mock",
sum = "h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=",
version = "v1.4.4",
name = "org_uber_go_mock",
importpath = "go.uber.org/mock",
sum = "h1:NEVjcPIj/L96qilPi+2M5l9zUkQksRaqNKphz3pStHI=",
version = "v0.1.0",
)

go_repository(
Expand Down
4 changes: 2 additions & 2 deletions gomock.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_context", "go_path")
load("@io_bazel_rules_go//go/private:providers.bzl", "GoLibrary", "GoPath")

_MOCKGEN_TOOL = "@com_github_golang_mock//mockgen"
_MOCKGEN_MODEL_LIB = "@com_github_golang_mock//mockgen/model:go_default_library"
_MOCKGEN_TOOL = "@org_uber_go_mock//mockgen"
_MOCKGEN_MODEL_LIB = "@org_uber_go_mock//mockgen/model:go_default_library"

def _gomock_source_impl(ctx):
go_ctx = go_context(ctx)
Expand Down
2 changes: 1 addition & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ go_test(
"fake_copyright.txt",
],
deps = [
"@com_github_golang_mock//gomock:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@com_github_google_go_cmp//cmp:go_default_library",
],
Expand Down
2 changes: 1 addition & 1 deletion tests/gomock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/golang/mock/gomock"
"go.uber.org/mock/gomock"
"github.com/google/go-cmp/cmp"
)

Expand Down

0 comments on commit 73ec599

Please sign in to comment.