Skip to content

Commit

Permalink
*: replace datadrive.Walk(t, "testdata" with `...testutils.TestData…
Browse files Browse the repository at this point in the history
…Path(t)`

Generated with:
```
ag '"testdata"' -G '_test\.go$' -l | xargs sed -i '' -e 's/datadriven.Walk(t, "testdata"/datadriven.Walk(t, testutils.TestDataPath(t)/g'
-- crlfmt and bazel generate
```

Release note: None
  • Loading branch information
otan committed Jan 19, 2022
1 parent ed1be85 commit e49415f
Show file tree
Hide file tree
Showing 26 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/multiregionccl/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestMultiRegionDataDriven(t *testing.T) {
skip.UnderRace(t, "flaky test")

ctx := context.Background()
datadriven.Walk(t, "testdata/", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
ds := datadrivenTestState{}
defer ds.cleanup(ctx)
var mu syncutil.Mutex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
func TestDataDriven(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
defer leaktest.AfterTest(t)()

var ts testState
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/multitenantccl/tenantcostserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDataDriven(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
defer leaktest.AfterTest(t)()

var ts testState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_test(
embed = [":tenanttokenbucket"],
deps = [
"//pkg/roachpb:with-mocks",
"//pkg/testutils",
"//pkg/util/leaktest",
"@com_github_cockroachdb_datadriven//:datadriven",
"@in_gopkg_yaml_v2//:yaml_v2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
"gopkg.in/yaml.v2"
Expand All @@ -24,7 +25,7 @@ import (
func TestDataDriven(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
defer leaktest.AfterTest(t)()

var ts testState
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/testfilter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_test(
data = glob(["testdata/**"]),
embed = [":testfilter_lib"],
deps = [
"//pkg/testutils",
"//pkg/util/leaktest",
"@com_github_cockroachdb_datadriven//:datadriven",
],
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/testfilter/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
)

func TestFilter(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
datadriven.RunTest(t, path, func(t *testing.T, td *datadriven.TestData) string {
in := strings.NewReader(td.Input)
var out strings.Builder
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvserver/loqrecovery/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ go_test(
"//pkg/roachpb:with-mocks",
"//pkg/storage",
"//pkg/storage/enginepb",
"//pkg/testutils",
"//pkg/util/hlc",
"//pkg/util/keysutil",
"//pkg/util/leaktest",
Expand Down
3 changes: 2 additions & 1 deletion pkg/kv/kvserver/loqrecovery/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/kv/kvserver/loqrecovery/loqrecoverypb"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
"github.com/stretchr/testify/require"
Expand All @@ -23,7 +24,7 @@ import (
func TestQuorumRecovery(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
env := quorumRecoveryEnv{}
defer env.cleanupStores()
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/tenantrate/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCloser(t *testing.T) {

func TestDataDriven(t *testing.T) {
defer leaktest.AfterTest(t)()
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
defer leaktest.AfterTest(t)()
datadriven.RunTest(t, path, new(testState).run)
})
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/colexec/execgen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_test(
data = glob(["testdata/**"]),
embed = [":execgen"],
deps = [
"//pkg/testutils",
"@com_github_cockroachdb_datadriven//:datadriven",
"@com_github_dave_dst//:dst",
"@com_github_dave_dst//decorator",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/colexec/execgen/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/datadriven"
"github.com/dave/dst/decorator"
)

// Walk walks path for datadriven files and calls RunTest on them.
func TestExecgen(t *testing.T) {
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
f, err := decorator.Parse(d.Input)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/idxconstraint/index_constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import (
func TestIndexConstraints(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
semaCtx := tree.MakeSemaContext()
evalCtx := tree.MakeTestingEvalContext(cluster.MakeTestingClusterSettings())

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/indexrec/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ go_test(
"//pkg/sql/opt/testutils/opttester",
"//pkg/sql/opt/testutils/testcat",
"//pkg/sql/types",
"//pkg/testutils",
"//pkg/util/leaktest",
"//pkg/util/log",
"@com_github_cockroachdb_datadriven//:datadriven",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/opt/indexrec/indexrec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/opttester"
"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/testcat"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/datadriven"
Expand All @@ -29,7 +30,7 @@ func TestIndexRec(t *testing.T) {

const fmtFlags = memo.ExprFmtHideStats | memo.ExprFmtHideRuleProps |
memo.ExprFmtHideQualifications | memo.ExprFmtHideScalars | memo.ExprFmtHideTypes
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
catalog := testcat.New()
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
tester := opttester.New(catalog, d.Input)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/optbuilder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
func TestBuilder(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
catalog := testcat.New()

datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/opt/optgen/cmd/optfmt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ go_test(
srcs = ["main_test.go"],
data = glob(["testdata/**"]),
embed = [":optfmt_lib"],
deps = ["@com_github_cockroachdb_datadriven//:datadriven"],
deps = [
"//pkg/testutils",
"@com_github_cockroachdb_datadriven//:datadriven",
],
)
3 changes: 2 additions & 1 deletion pkg/sql/opt/optgen/cmd/optfmt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/datadriven"
)

func TestPretty(t *testing.T) {
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
datadriven.RunTest(t, path, prettyTest)
})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/optgen/exprgen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go_test(
deps = [
"//pkg/sql/opt/testutils/opttester",
"//pkg/sql/opt/testutils/testcat",
"//pkg/testutils",
"@com_github_cockroachdb_datadriven//:datadriven",
],
)
3 changes: 2 additions & 1 deletion pkg/sql/opt/optgen/exprgen/expr_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (

"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/opttester"
"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/testcat"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/datadriven"
)

func TestExprGen(t *testing.T) {
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
catalog := testcat.New()
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
tester := opttester.New(catalog, d.Input)
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/testutils/opttester/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ go_test(
":opttester",
"//pkg/sql/opt/memo",
"//pkg/sql/opt/testutils/testcat",
"//pkg/testutils",
"@com_github_cockroachdb_datadriven//:datadriven",
],
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/opt/testutils/opttester/opt_tester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/opttester"
"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/testcat"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/datadriven"
)

func TestOptTester(t *testing.T) {
const fmtFlags = memo.ExprFmtHideStats | memo.ExprFmtHideCost | memo.ExprFmtHideRuleProps |
memo.ExprFmtHideQualifications

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
if strings.HasSuffix(path, ".json") {
// Skip any .json files; used for inject-stats
return
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/testutils/testcat/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ go_test(
deps = [
":testcat",
"//pkg/sql/opt/testutils/opttester",
"//pkg/testutils",
"//pkg/util/leaktest",
"@com_github_cockroachdb_datadriven//:datadriven",
],
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/opt/testutils/testcat/test_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (

"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/opttester"
"github.com/cockroachdb/cockroach/pkg/sql/opt/testutils/testcat"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
)

func TestCatalog(t *testing.T) {
defer leaktest.AfterTest(t)()

datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
catalog := testcat.New()

datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// TestParseDataDriven verifies that we can parse the supplied SQL and regenerate the SQL
// string from the syntax tree.
func TestParseDatadriven(t *testing.T) {
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
switch d.Cmd {
case "parse":
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/sqlstats/persistedsqlstats/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sqlstats"
"github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats"
"github.com/cockroachdb/cockroach/pkg/sql/tests"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand Down Expand Up @@ -152,7 +153,7 @@ func TestSQLStatsDataDriven(t *testing.T) {
return ""
}

datadriven.Walk(t, "testdata/", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) {
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
if d.Cmd == "register-callback" {
mustHaveArgsOrFatal(
Expand Down

0 comments on commit e49415f

Please sign in to comment.