sourcegraph/cmd/frontend/internal/executorqueue/queues/batches/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

73 lines
2.0 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 = "batches",
srcs = [
"queue.go",
"transform.go",
],
importpath = "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/executorqueue/queues/batches",
visibility = ["//cmd/frontend:__subpackages__"],
deps = [
"//cmd/frontend/graphqlbackend",
"//cmd/frontend/internal/executorqueue/handler",
"//internal/actor",
"//internal/batches/store",
"//internal/batches/types",
"//internal/conf",
"//internal/database",
"//internal/encryption/keyring",
"//internal/executor/types",
"//internal/executor/util",
"//internal/observation",
"//lib/api",
"//lib/batches",
"//lib/batches/template",
"//lib/errors",
"@com_github_kballard_go_shellquote//:go-shellquote",
"@com_github_sourcegraph_log//:log",
],
)
go_test(
name = "batches_test",
timeout = "short",
srcs = [
"mocks_test.go",
"transform_test.go",
],
embed = [":batches"],
deps = [
"//cmd/frontend/graphqlbackend",
"//internal/api",
"//internal/batches/store",
"//internal/batches/types",
"//internal/conf",
"//internal/database",
"//internal/database/dbmocks",
"//internal/executor/types",
"//internal/types",
"//lib/batches",
"//lib/batches/execution",
"//lib/batches/template",
"//schema",
"@com_github_derision_test_go_mockgen//testutil/assert",
"@com_github_google_go_cmp//cmp",
"@com_github_sourcegraph_log//logtest",
"@in_gopkg_yaml_v2//:yaml_v2",
],
)
go_mockgen(
name = "generate_mocks",
out = "mocks_test.go",
manifests = [
"//:mockgen.yaml",
"//:mockgen.test.yaml",
"//:mockgen.temp.yaml",
],
deps = [":batches"],
)