cockroachdb / cockroachdb/cockroach

bazel: support disallowed_imports_test for go_test target

Open
#106,957 0 comments 0 reactions 0 assignees View on GitHub
A-build-system C-cleanup T-dev-inf
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

I'd like to have the ability to create a new package that only contains tests and enforce that this test package doesn't import a particular package (e.g. `ccl`). This can be useful for some tests that assume that `ccl` package is not loaded. I tried the existing `disallowed_imports_test` utility with:
```
disallowed_imports_test(
src = "sqlnoccltest_test",
disallowed_prefixes = [
"pkg/ccl/",
],
)
```
but it failed with
```
ERROR: /Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlnoccltest/BUILD.bazel:30:24: in src attribute of _deps_rule rule //pkg/sql/sqlnoccltest:sqlnoccltest_test_disallowed_imports_script: '//pkg/sql/sqlnoccltest:sqlnoccltest_test' does not have mandatory providers: 'GoLibrary'. Since this rule was created by the macro 'disallowed_imports_test', the error might have been caused by the macro implementation
ERROR: /Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlnoccltest/BUILD.bazel:30:24: Analysis of target '//pkg/sql/sqlnoccltest:sqlnoccltest_test_disallowed_imports_script' failed
```
Some context is in https://cockroachlabs.slack.com/archives/C019A8NANH0/p1689631171337059.

Epic: CRDB-17171
Jira issue: CRDB-29776

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.