Skip to content

Commit

Permalink
*: replace "testdata/..." with testutils.TestDataPath
Browse files Browse the repository at this point in the history
Also try and break down `/` as much as possible.

```
-- fix the slashes
ag '"testdata/' -G '_test\.go$' pkg -l | xargs sed -i '' -e 's/"testdata\/\([^"]*\)"/testutils.TestDataPath(t, "\1")/g'
git diff --name-only | xargs sed -i '' -e 's_filepath.Join(testutils.TestDataPath(), "\([^/]*\)/\([^"]*\)"_testutils.TestDataPath(t, "\1", "\2")_g'
git diff --name-only | xargs sed -i '' -e 's_filepath.Join(testutils.TestDataPath()\(.*,\) "\([^/]*\)/\([^"]*\)"_testutils.TestDataPath(t\1 "\2", "\3")_g'

-- crlfmt and make generate
```

Also some manual fixes unfortunately...

Release note: None
  • Loading branch information
otan committed Jan 19, 2022
1 parent e49415f commit 58bb285
Show file tree
Hide file tree
Showing 84 changed files with 179 additions and 112 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestBackupRestoreDataDriven(t *testing.T) {
defer httpServerCleanup()

ctx := context.Background()
datadriven.Walk(t, "testdata/backup-restore/", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t, "backup-restore", ""), func(t *testing.T, path string) {
var lastCreatedServer string
ds := newDatadrivenTestState()
defer ds.cleanup(ctx)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/backupccl/restore_mid_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestRestoreMidSchemaChange(t *testing.T) {

skip.UnderRaceWithIssue(t, 56584)

const (
testdataBase = "testdata/restore_mid_schema_change"
var (
testdataBase = testutils.TestDataPath(t, "restore_mid_schema_change")
exportDirs = testdataBase + "/exports"
)
for _, isClusterRestore := range []bool{true, false} {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ccl/backupccl/restore_old_sequences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/stretchr/testify/require"
Expand All @@ -41,8 +42,8 @@ import (
func TestRestoreOldSequences(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
const (
testdataBase = "testdata/restore_old_sequences"
var (
testdataBase = testutils.TestDataPath(t, "restore_old_sequences")
exportDirs = testdataBase + "/exports"
)

Expand Down
12 changes: 6 additions & 6 deletions pkg/ccl/backupccl/restore_old_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import (
func TestRestoreOldVersions(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
const (
testdataBase = "testdata/restore_old_versions"
testdataBase := testutils.TestDataPath(t, "restore_old_versions")
var (
exportDirsWithoutInterleave = testdataBase + "/exports-without-interleaved"
exportDirs = testdataBase + "/exports"
fkRevDirs = testdataBase + "/fk-rev-history"
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestRestoreOldBackupMissingOfflineIndexes(t *testing.T) {
skip.UnderRace(t, "times out under race cause it starts up two test servers")
ctx := context.Background()

badBackups, err := filepath.Abs("testdata/restore_old_versions/inc_missing_addsst/v20.2.7")
badBackups, err := filepath.Abs(testutils.TestDataPath(t, "restore_old_versions", "inc_missing_addsst", "v20.2.7"))
require.NoError(t, err)
args := base.TestServerArgs{ExternalIODir: badBackups}
backupDirs := make([]string, 9)
Expand Down Expand Up @@ -728,10 +728,10 @@ func TestRestoreWithDroppedSchemaCorruption(t *testing.T) {
defer log.Scope(t).Close(t)
ctx := context.Background()

backupDir := testutils.TestDataPath(t, "restore_with_dropped_schema", "exports", "v20.2.7")
const (
dbName = "foo"
backupDir = "testdata/restore_with_dropped_schema/exports/v20.2.7"
fromDir = "nodelocal://0/"
dbName = "foo"
fromDir = "nodelocal://0/"
)

args := base.TestServerArgs{ExternalIODir: backupDir}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ func TestShowUpgradedForeignKeys(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

const (
testdataBase = "testdata/restore_old_versions"
var (
testdataBase = testutils.TestDataPath(t, "restore_old_versions")
fkRevDirs = testdataBase + "/fk-rev-history"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/ccl/importccl/import_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/sql/rowexec"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"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/ctxgroup"
Expand Down Expand Up @@ -999,7 +1000,7 @@ func avroFormat(t *testing.T, format roachpb.AvroOptions_Format) roachpb.IOFileF

if format != roachpb.AvroOptions_OCF {
// Need to load schema for record specific inputs.
bytes, err := ioutil.ReadFile("testdata/avro/simple-schema.json")
bytes, err := ioutil.ReadFile(testutils.TestDataPath(t, "avro", "simple-schema.json"))
require.NoError(t, err)
avro.SchemaJSON = string(bytes)
avro.RecordSeparator = '\n'
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/importccl/mysql_testdata_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ func getMysqlOutfileTestdata(t *testing.T) ([]simpleTestRow, []outfileDumpCfg) {
}

for i := range configs {
configs[i].filename = filepath.Join(`testdata`, `mysqlout`, configs[i].name, `simple.txt`)
configs[i].filename = testutils.TestDataPath(t, `mysqlout`, configs[i].name, `simple.txt`)
}

if rewriteMysqlTestData {
genMysqlTestdata(t, func() {
if err := os.RemoveAll(filepath.Join(`testdata`, `mysqlout`)); err != nil {
if err := os.RemoveAll(testutils.TestDataPath(t, `mysqlout`)); err != nil {
t.Fatal(err)
}
for _, cfg := range configs {
Expand Down
7 changes: 4 additions & 3 deletions pkg/ccl/importccl/read_import_avro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/parser"
"github.com/cockroachdb/cockroach/pkg/sql/row"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/linkedin/goavro/v2"
Expand Down Expand Up @@ -524,7 +525,7 @@ var _ importRowProducer = &limitAvroStream{}
func BenchmarkOCFImport(b *testing.B) {
benchmarkAvroImport(b, roachpb.AvroOptions{
Format: roachpb.AvroOptions_OCF,
}, "testdata/avro/stock-10000.ocf")
}, testutils.TestDataPath(b, "avro", "stock-10000.ocf"))
}

// goos: darwin
Expand All @@ -541,13 +542,13 @@ func BenchmarkOCFImport(b *testing.B) {
// BenchmarkBinaryJSONImport-16 500000 3215 ns/op 37.32 MB/s
// BenchmarkBinaryJSONImport-16 500000 3235 ns/op 37.09 MB/s
func BenchmarkBinaryJSONImport(b *testing.B) {
schemaBytes, err := ioutil.ReadFile("testdata/avro/stock-schema.json")
schemaBytes, err := ioutil.ReadFile(testutils.TestDataPath(b, "avro", "stock-schema.json"))
require.NoError(b, err)

benchmarkAvroImport(b, roachpb.AvroOptions{
Format: roachpb.AvroOptions_BIN_RECORDS,
SchemaJSON: string(schemaBytes),
}, "testdata/avro/stock-10000.bjson")
}, testutils.TestDataPath(b, "avro", "stock-10000.bjson"))
}

func benchmarkAvroImport(b *testing.B, avroOpts roachpb.AvroOptions, testData string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/kvccl/kvfollowerreadsccl/boundedstaleness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestBoundedStalenessDataDriven(t *testing.T) {
return errorRegexp.ReplaceAllString(s, "$1 XXX")
}

datadriven.Walk(t, "testdata/boundedstaleness", func(t *testing.T, path string) {
datadriven.Walk(t, testutils.TestDataPath(t, "boundedstaleness"), func(t *testing.T, path string) {
tc := testcluster.StartTestCluster(t, 3, clusterArgs)
defer tc.Stopper().Stop(ctx)

Expand Down
3 changes: 2 additions & 1 deletion pkg/ccl/sqlproxyccl/frontend_admitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"crypto/tls"
"fmt"
"net"
"path/filepath"
"testing"

"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand All @@ -23,7 +24,7 @@ import (
)

func tlsConfig() (*tls.Config, error) {
cer, err := tls.LoadX509KeyPair("testdata/testserver.crt", "testdata/testserver.key")
cer, err := tls.LoadX509KeyPair(filepath.Join("testdata", "testserver.crt"), filepath.Join("testdata", "testserver.key"))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/sqlproxyccl/proxy_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,8 @@ openssl genrsa -out testdata/testserver.key 2048
openssl req -new -x509 -sha256 -key testdata/testserver.key -out testdata/testserver.crt \
-days 3650 -config testdata/testserver_config.cnf
`
opts.ListenKey = "testdata/testserver.key"
opts.ListenCert = "testdata/testserver.crt"
opts.ListenKey = testutils.TestDataPath(t, "testserver.key")
opts.ListenCert = testutils.TestDataPath(t, "testserver.crt")

return newProxyServer(ctx, t, stopper, opts)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/ccl/storageccl/engineccl/pebble_key_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/ccl/storageccl/engineccl/enginepbccl"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -246,7 +247,7 @@ func TestDataKeyManager(t *testing.T) {
return timeutil.Unix(unixTime, 0)
}

datadriven.RunTest(t, "testdata/data_key_manager",
datadriven.RunTest(t, testutils.TestDataPath(t, "data_key_manager"),
func(t *testing.T, d *datadriven.TestData) string {
switch d.Cmd {
case "init":
Expand Down Expand Up @@ -405,7 +406,7 @@ func TestDataKeyManagerIO(t *testing.T) {

var dkm *DataKeyManager

datadriven.RunTest(t, "testdata/data_key_manager_io",
datadriven.RunTest(t, testutils.TestDataPath(t, "data_key_manager_io"),
func(t *testing.T, d *datadriven.TestData) string {
fmt.Println(d.Pos)
buf.Reset()
Expand Down
9 changes: 5 additions & 4 deletions pkg/cli/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestDoctorCluster(t *testing.T) {
}

// Using datadriven allows TESTFLAGS=-rewrite.
datadriven.RunTest(t, "testdata/doctor/test_examine_cluster", func(t *testing.T, td *datadriven.TestData) string {
datadriven.RunTest(t, testutils.TestDataPath(t, "doctor", "test_examine_cluster"), func(t *testing.T, td *datadriven.TestData) string {
return out
})
})
Expand All @@ -62,7 +63,7 @@ func TestDoctorZipDir(t *testing.T) {
}

// Using datadriven allows TESTFLAGS=-rewrite.
datadriven.RunTest(t, "testdata/doctor/test_examine_zipdir", func(t *testing.T, td *datadriven.TestData) string {
datadriven.RunTest(t, testutils.TestDataPath(t, "doctor", "test_examine_zipdir"), func(t *testing.T, td *datadriven.TestData) string {
return out
})
})
Expand All @@ -74,7 +75,7 @@ func TestDoctorZipDir(t *testing.T) {
}

// Using datadriven allows TESTFLAGS=-rewrite.
datadriven.RunTest(t, "testdata/doctor/test_recreate_zipdir", func(t *testing.T, td *datadriven.TestData) string {
datadriven.RunTest(t, testutils.TestDataPath(t, "doctor", "test_recreate_zipdir"), func(t *testing.T, td *datadriven.TestData) string {
return out
})
})
Expand All @@ -86,7 +87,7 @@ func TestDoctorZipDir(t *testing.T) {
}

// Using datadriven allows TESTFLAGS=-rewrite.
datadriven.RunTest(t, "testdata/doctor/test_examine_zipdir_verbose", func(t *testing.T, td *datadriven.TestData) string {
datadriven.RunTest(t, testutils.TestDataPath(t, "doctor", "test_examine_zipdir_verbose"), func(t *testing.T, td *datadriven.TestData) string {
return out
})
})
Expand Down
10 changes: 5 additions & 5 deletions pkg/cli/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestImportCLI(t *testing.T) {
{
"pgdump",
"PGDUMP",
"testdata/import/db.sql",
testutils.TestDataPath(t, "import", "db.sql"),
"",
"IMPORT PGDUMP 'userfile://defaultdb.public.userfiles_root/db." +
"sql' WITH max_row_size='524288'",
Expand All @@ -117,7 +117,7 @@ func TestImportCLI(t *testing.T) {
{
"pgdump-with-options",
"PGDUMP",
"testdata/import/db.sql",
testutils.TestDataPath(t, "import", "db.sql"),
"--max-row-size=1000 --skip-foreign-keys=true --row-limit=10 " +
"--ignore-unsupported-statements=true --log-ignored-statements='foo://bar'",
"IMPORT PGDUMP 'userfile://defaultdb.public.userfiles_root/db." +
Expand All @@ -131,7 +131,7 @@ func TestImportCLI(t *testing.T) {
{
"pgdump-to-target-database",
"PGDUMP",
"testdata/import/db.sql",
testutils.TestDataPath(t, "import", "db.sql"),
"--ignore-unsupported-statements=true --url=postgresql:///baz",
"IMPORT PGDUMP 'userfile://defaultdb.public.userfiles_root/db." +
"sql' WITH max_row_size='524288', ignore_unsupported_statements",
Expand All @@ -142,7 +142,7 @@ func TestImportCLI(t *testing.T) {
{
"mysql",
"MYSQLDUMP",
"testdata/import/db.sql",
testutils.TestDataPath(t, "import", "db.sql"),
"",
"IMPORT MYSQLDUMP 'userfile://defaultdb.public.userfiles_root/db.sql'",
"IMPORT TABLE foo FROM MYSQLDUMP 'userfile://defaultdb.public.userfiles_root/db.sql'",
Expand All @@ -151,7 +151,7 @@ func TestImportCLI(t *testing.T) {
{
"mysql-with-options",
"MYSQLDUMP",
"testdata/import/db.sql",
testutils.TestDataPath(t, "import", "db.sql"),
"--skip-foreign-keys=true --row-limit=10",
"IMPORT MYSQLDUMP 'userfile://defaultdb.public.userfiles_root/db." +
"sql' WITH skip_foreign_keys, row_limit='10'",
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/log_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/log/logconfig"
Expand Down Expand Up @@ -129,7 +130,7 @@ func TestSetupLogging(t *testing.T) {

ctx := context.Background()

datadriven.RunTest(t, "testdata/logflags", func(t *testing.T, td *datadriven.TestData) string {
datadriven.RunTest(t, testutils.TestDataPath(t, "logflags"), func(t *testing.T, td *datadriven.TestData) string {
args := strings.Split(td.Input, "\n")

initCLIDefaults()
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/statement_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"context"
"net/url"
"os"
"path/filepath"
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/cli/clisqlclient"
"github.com/cockroachdb/cockroach/pkg/cli/clisqlexec"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestRunExplainCombinations(t *testing.T) {
defer cleanupFn()
conn := c.ConnCtx.MakeSQLConn(os.Stdout, os.Stdout, pgURL.String())
for _, test := range tests {
bundle, err := loadStatementBundle(filepath.Join("testdata/explain-bundle", test.bundlePath))
bundle, err := loadStatementBundle(testutils.TestDataPath(t, "explain-bundle", test.bundlePath))
assert.NoError(t, err)
// Disable autostats collection, which will override the injected stats.
if err := conn.Exec(`SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false`, nil); err != nil {
Expand Down
Loading

0 comments on commit 58bb285

Please sign in to comment.