Skip to content

Commit

Permalink
Merge #70875
Browse files Browse the repository at this point in the history
70875: dev: refactor `setupPath` test in `dev` r=rail a=rickystewart

We used to run this on every single test case in `dev`, which would
require copy-pasting a bunch of boilerplate every time you add a test
case. Instead refactor the `setupPath` test out on its own and test it
just once.

Release note: None

Co-authored-by: Ricky Stewart <ricky@cockroachlabs.com>
  • Loading branch information
craig[bot] and rickystewart committed Sep 30, 2021
2 parents fb5b6bb + afc96e7 commit bd732cb
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 500 deletions.
5 changes: 4 additions & 1 deletion pkg/cmd/dev/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ go_binary(

go_test(
name = "dev_test",
srcs = ["datadriven_test.go"],
srcs = [
"datadriven_test.go",
"dev_test.go",
],
data = glob(["testdata/**"]),
embed = [":dev_lib"],
deps = [
Expand Down
5 changes: 0 additions & 5 deletions pkg/cmd/dev/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import (
"github.com/stretchr/testify/require"
)

func init() {
isTesting = true
}

// TestDatadriven makes use of datadriven to play back all operations executed
// by individual `dev` invocations. The testcases are defined under testdata/*,
// where each test files corresponds to a recording capture found in
Expand Down Expand Up @@ -88,7 +84,6 @@ func TestDatadriven(t *testing.T) {
dev := makeDevCmd()
dev.exec = devExec
dev.os = devOS
require.NoError(t, setupPath(dev))

if !verbose {
dev.cli.SetErr(ioutil.Discard)
Expand Down
62 changes: 62 additions & 0 deletions pkg/cmd/dev/dev_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package main

import (
"bytes"
"io"
"log"
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/cmd/dev/io/exec"
"github.com/cockroachdb/cockroach/pkg/cmd/dev/io/os"
"github.com/cockroachdb/cockroach/pkg/cmd/dev/recording"
"github.com/stretchr/testify/require"
)

func init() {
isTesting = true
}

func TestSetupPath(t *testing.T) {
rec := `getenv PATH
----
/usr/local/opt/ccache/libexec:/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
which cc
----
/usr/local/opt/ccache/libexec/cc
readlink /usr/local/opt/ccache/libexec/cc
----
../bin/ccache
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
----
`
r := recording.WithReplayFrom(strings.NewReader(rec), "TestSetupPath")
var logger io.ReadWriter = bytes.NewBufferString("")
var exopts []exec.Option
exopts = append(exopts, exec.WithRecording(r))
exopts = append(exopts, exec.WithLogger(log.New(logger, "", 0)))
var osopts []os.Option
osopts = append(osopts, os.WithRecording(r))
osopts = append(osopts, os.WithLogger(log.New(logger, "", 0)))
devExec := exec.New(exopts...)
devOS := os.New(osopts...)
dev := makeDevCmd()
dev.exec = devExec
dev.os = devOS

require.NoError(t, setupPath(dev))
}
8 changes: 0 additions & 8 deletions pkg/cmd/dev/testdata/bench.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
dev bench pkg/util/...
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
git grep -l ^func Benchmark -- pkg/util/*_test.go
bazel run --config=test --test_sharding_strategy=disabled //pkg/util:util_test -- -test.run=- -test.bench=.
bazel run --config=test --test_sharding_strategy=disabled //pkg/util/uuid:uuid_test -- -test.run=- -test.bench=.

dev bench pkg/sql/parser --filter=BenchmarkParse
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel run --config=test --test_sharding_strategy=disabled //pkg/sql/parser:parser_test -- -test.run=- -test.bench=BenchmarkParse
28 changes: 0 additions & 28 deletions pkg/cmd/dev/testdata/build.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
dev build cockroach-short
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build //pkg/cmd/cockroach-short
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand All @@ -13,10 +9,6 @@ ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroac

dev build cockroach-short --cpus=12
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build --local_cpu_resources=12 //pkg/cmd/cockroach-short
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand All @@ -26,10 +18,6 @@ ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroac

dev build --debug cockroach-short
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build //pkg/cmd/cockroach-short
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand All @@ -39,10 +27,6 @@ ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroac

dev build cockroach-short --remote-cache 127.0.0.1:9090
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build --remote_local_fallback --remote_cache=grpc://127.0.0.1:9090 --experimental_remote_downloader=grpc://127.0.0.1:9090 //pkg/cmd/cockroach-short
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand All @@ -52,10 +36,6 @@ ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroac

dev build cockroach-short --hoist-generated-code
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build //pkg/cmd/cockroach-short
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand All @@ -71,10 +51,6 @@ cp /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroach/b

dev build short -- -s
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build //pkg/cmd/cockroach-short -s
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand All @@ -84,10 +60,6 @@ ln -s /private/var/tmp/_bazel/99e666e4e674209ecdb66b46371278df/execroot/cockroac

dev build -- --verbose_failures --sandbox_debug
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel build //pkg/cmd/cockroach --verbose_failures --sandbox_debug
bazel info workspace --color=no
mkdir go/src/github.com/cockroachdb/cockroach/bin
Expand Down
8 changes: 0 additions & 8 deletions pkg/cmd/dev/testdata/builder.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
dev builder
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
id
bazel info workspace --color=no
cat go/src/github.com/cockroachdb/cockroach/build/teamcity-bazel-support.sh
Expand All @@ -13,10 +9,6 @@ docker run --rm -it -v go/src/github.com/cockroachdb/cockroach:/cockroach --work

dev builder echo hi
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
id
bazel info workspace --color=no
cat go/src/github.com/cockroachdb/cockroach/build/teamcity-bazel-support.sh
Expand Down
12 changes: 0 additions & 12 deletions pkg/cmd/dev/testdata/generate.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
dev gen bazel
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel info workspace --color=no
go/src/github.com/cockroachdb/cockroach/build/bazelutil/bazel-generate.sh

dev gen docs
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel info workspace --color=no
cat go/src/github.com/cockroachdb/cockroach/docs/generated/bazel_targets.txt
bazel build //docs/generated:gen-logging-md //docs/generated/sql
Expand All @@ -29,10 +21,6 @@ echo MOCK_REDACT_SAFE_OUTPUT > go/src/github.com/cockroachdb/cockroach/docs/gene

dev gen go
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel info workspace --color=no
cat go/src/github.com/cockroachdb/cockroach/build/bazelutil/checked_in_genfiles.txt
bazel build //pkg/roachpb:gen-batch-generated //pkg/sql/opt/optgen/lang:gen-expr //pkg/sql/opt/optgen/lang:gen-operator
Expand Down
8 changes: 0 additions & 8 deletions pkg/cmd/dev/testdata/lint.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
dev lint
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel run --config=test //build/bazelutil:lint -- -test.v

dev lint --short --timeout=5m
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel run --config=test //build/bazelutil:lint -- -test.v -test.short -test.timeout 5m0s
30 changes: 0 additions & 30 deletions pkg/cmd/dev/testdata/recording/bench.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
getenv PATH
----
/usr/local/opt/ccache/libexec:/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin

which cc
----
/usr/local/opt/ccache/libexec/cc

readlink /usr/local/opt/ccache/libexec/cc
----
../bin/ccache

export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
----

git grep -l ^func Benchmark -- pkg/util/*_test.go
----
pkg/util/topk_test.go
Expand All @@ -26,20 +11,5 @@ bazel run --config=test --test_sharding_strategy=disabled //pkg/util:util_test -
bazel run --config=test --test_sharding_strategy=disabled //pkg/util/uuid:uuid_test -- -test.run=- -test.bench=.
----

getenv PATH
----
/usr/local/opt/ccache/libexec:/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin

which cc
----
/usr/local/opt/ccache/libexec/cc

readlink /usr/local/opt/ccache/libexec/cc
----
../bin/ccache

export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
----

bazel run --config=test --test_sharding_strategy=disabled //pkg/sql/parser:parser_test -- -test.run=- -test.bench=BenchmarkParse
----
Loading

0 comments on commit bd732cb

Please sign in to comment.