sourcegraph/internal/gitserver/BUILD.bazel
Noah S-C 19d9cfc73b
bazel: native go-mockgen in Bazel (#60386)
Adds a new:
- gazelle generator
- rule + rule targets + catchall target
for generating go-mockgen mocks & testing for their being up-to-date.

Each go_mockgen macro invocation adds targets for generating mocks, copying to the source tree, as well as testing whether the current source tree mocks are up-to-date.

How to use this: `bazel run //dev:go_mockgen` for the catch-all, or `bazel run //some/target:generate_mocks` for an individual package, and `bazel test //some/target:generate_mocks_tests` to test for up-to-date-ness. There is no catch-all for testing

This currently uses a fork of go-mockgen, with an open PR for upstream here: https://github.com/derision-test/go-mockgen/pull/50.

Closes https://github.com/sourcegraph/sourcegraph/issues/60099

## Test plan

Extensive testing during development, including the following cases:
- Deleting a generated file and its entry in a go_library/go_test `srcs` attribute list and then re-running `sg bazel configure`
- Adding a non-existent output directory to mockgen.test.yaml and running the bash one-liner emitted to prepare the workspace for rerunning `sg bazel configure`

The existing config tests a lot of existing paths anyway (creating mocks for a 3rd party library's interface, entries for a given output file in >1 config file etc)
2024-02-16 13:26:48 +00:00

107 lines
3.3 KiB
Python

load("//dev:go_mockgen.bzl", "go_mockgen")
load("//dev:go_defs.bzl", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "gitserver",
srcs = [
"addrs.go",
"client.go",
"commands.go",
"errwrap.go",
"git_command.go",
"mock.go",
"mocks_temp.go",
"observability.go",
"retry.go",
"stream_client.go",
"test_utils.go",
],
importpath = "github.com/sourcegraph/sourcegraph/internal/gitserver",
visibility = ["//:__subpackages__"],
deps = [
"//internal/actor",
"//internal/api",
"//internal/authz",
"//internal/byteutils",
"//internal/conf",
"//internal/extsvc/gitolite",
"//internal/fileutil",
"//internal/gitserver/gitdomain",
"//internal/gitserver/protocol",
"//internal/gitserver/v1:gitserver",
"//internal/grpc/defaults",
"//internal/grpc/streamio",
"//internal/lazyregexp",
"//internal/metrics",
"//internal/observation",
"//internal/perforce",
"//internal/search/streaming/http",
"//lib/errors",
"//lib/pointers",
"@com_github_go_git_go_git_v5//plumbing/format/config",
"@com_github_golang_groupcache//lru",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_golang//prometheus/promauto",
"@com_github_sourcegraph_conc//pool",
"@com_github_sourcegraph_go_diff//diff",
"@com_github_sourcegraph_log//:log",
"@com_github_sourcegraph_log//logtest",
"@io_opentelemetry_go_otel//attribute",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//metadata",
"@org_golang_google_grpc//status",
],
)
go_test(
name = "gitserver_test",
timeout = "short",
srcs = [
"addrs_test.go",
"client_test.go",
"commands_test.go",
"grpc_test.go",
"internal_test.go",
],
embed = [":gitserver"],
# This test loads coursier as a side effect, so we ensure the
# path is sandboxed properly.
env = {"COURSIER_CACHE_DIR": "/tmp"},
deps = [
"//internal/actor",
"//internal/api",
"//internal/authz",
"//internal/conf",
"//internal/conf/conftypes",
"//internal/database/dbmocks",
"//internal/extsvc/gitolite",
"//internal/gitserver/gitdomain",
"//internal/gitserver/protocol",
"//internal/gitserver/v1:gitserver",
"//internal/grpc",
"//lib/errors",
"//schema",
"@com_github_google_go_cmp//cmp",
"@com_github_sourcegraph_go_diff//diff",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//status",
"@org_golang_google_protobuf//types/known/timestamppb",
],
)
go_mockgen(
name = "generate_mocks",
out = "mock.go",
manifests = [
"//:mockgen.yaml",
"//:mockgen.test.yaml",
"//:mockgen.temp.yaml",
],
deps = ["//internal/gitserver/v1:gitserver"],
)