Skip to content

Commit

Permalink
dev: error when trying to dev test a bazel tested target
Browse files Browse the repository at this point in the history
Running `dev test` on these integration tests will
always fail, so this PR adds an error when running
the command on those files.

Fixes: #107813
Release note: None
  • Loading branch information
Liam Gillies committed Aug 23, 2023
1 parent a03be32 commit e6e8b64
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/cmd/dev/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ const (
showDiffFlag = "show-diff"
)

// List of bazel integration tests that will fail when running `dev test pkg/...`
var integrationTests = map[string]struct{ testName, commandToRun string }{
"pkg/acceptance": {"acceptance_test", "dev acceptance"},
"pkg/compose": {"compose_test", "dev compose"},
"pkg/compose/compare/compare": {"compare_test", "dev compose"},
"pkg/testutils/docker": {"docker_test", ""},
"pkg/testutils/lint": {"lint_test", "dev lint"},
}

func makeTestCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Command {
// testCmd runs the specified cockroachdb tests.
testCmd := &cobra.Command{
Expand Down Expand Up @@ -257,6 +266,20 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error {
testTargets = append(testTargets, target)
}

for _, target := range testTargets {
testTarget := strings.Split(target, ":")
integrationTest, ok := integrationTests[testTarget[0]]
if ok {
// If the test targets all tests in the package or the individual test, warn the user
if testTarget[1] == "all" || testTarget[1] == integrationTest.testName {
if integrationTest.commandToRun == "" {
return fmt.Errorf("%s:%s will fail since it is an integration test", testTarget[0], integrationTest.testName)
}
return fmt.Errorf("%s:%s will fail since it is an integration test. To run this test, run `%s`", testTarget[0], integrationTest.testName, integrationTest.commandToRun)
}
}
}

args = append(args, testTargets...)
if ignoreCache {
args = append(args, "--nocache_test_results")
Expand Down

0 comments on commit e6e8b64

Please sign in to comment.