Skip to content

Commit bb4128e

Browse files
authored
Copying gomock definition and tests from rules_go (#231)
This PR copies the gomock definition and tests from rules_go with minimal changes: * Replacing github.com/golang/mock with go.uber.org/mock * Replacing `load` statements accordingly * Setting up a Bazel and a Go module in the "bazel" directory Note that the Go module uses v0.4.0 of go.uber.org/mock, because the latest version is no longer compatible with the gomock rule (bazel-contrib/rules_go#4153). We will update the rule and mockgen version in subsequent PRs. This is a first step in addressing #225
1 parent d97cf0d commit bb4128e

File tree

21 files changed

+654
-3
lines changed

21 files changed

+654
-3
lines changed

.github/workflows/test.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
test:
12+
go:
1313
strategy:
1414
matrix:
1515
go-version: [1.22.x, 1.23.x] # oldest version that can build go mock and official supported go versions
@@ -40,10 +40,35 @@ jobs:
4040
./ci/test.sh
4141
./ci/check_panic_handling.sh
4242
43-
- name: Run Tests
43+
- name: Run Go Tests
4444
run: |
45-
for i in $(find $PWD -name go.mod); do
45+
for i in $(find $PWD -name go.mod ! -path "$PWD/bazel/go.mod"); do
4646
pushd $(dirname $i)
4747
go test ./...
4848
popd
4949
done
50+
51+
bazel:
52+
strategy:
53+
matrix:
54+
os:
55+
- macos
56+
- ubuntu
57+
runs-on: ${{ matrix.os }}-latest
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
62+
- name: Setup Bazel
63+
uses: bazel-contrib/[email protected]
64+
with:
65+
# Avoid downloading Bazel every time.
66+
bazelisk-cache: true
67+
# Store build cache per workflow.
68+
disk-cache: ${{ github.workflow }}
69+
# Share repository cache between workflows.
70+
repository-cache: true
71+
72+
- name: Run Bazel tests
73+
run: |
74+
cd bazel && bazel test //...

bazel/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bazel-*
2+
MODULE.bazel.lock

bazel/BUILD.bazel

Whitespace-only changes.

bazel/MODULE.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module(name = "bazel_gomock")
2+
3+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
4+
bazel_dep(name = "rules_go", version = "0.51.0", repo_name = "io_bazel_rules_go")
5+
bazel_dep(name = "gazelle", version = "0.40.0")
6+
7+
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
8+
9+
go_sdk.download(version = "1.23.4")
10+
11+
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
12+
go_deps.from_file(go_mod = "//:go.mod")
13+
use_repo(
14+
go_deps,
15+
"org_uber_go_mock",
16+
)

bazel/WORKSPACE

Whitespace-only changes.

bazel/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module go.uber.org/mock/bazel
2+
3+
go 1.23.0
4+
5+
require go.uber.org/mock v0.4.0

bazel/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
2+
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=

bazel/rules/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "rules",
5+
srcs = ["tools.go"],
6+
importpath = "go.uber.org/mock/bazel/rules",
7+
visibility = ["//visibility:public"],
8+
deps = ["@org_uber_go_mock//mockgen/model:go_default_library"],
9+
)

0 commit comments

Comments
 (0)