Skip to content

Commit

Permalink
cli,userfile,jobs,ptstorage: remove calls to CreateTestServerParams
Browse files Browse the repository at this point in the history
This commit adjusts tests in these package to run with the test tenant.

Note that the test tenant won't still run in `cli` because `ccl` isn't
linked (I briefly tried, and I think there was an import cycle - the
longer term fix is to move tests into `cli_test` package, but it's left
for later).

Release note: None
  • Loading branch information
yuzefovich committed Jul 26, 2023
1 parent 239a068 commit 6035b1a
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 82 deletions.
1 change: 0 additions & 1 deletion pkg/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ go_test(
"//pkg/sql/catalog/descpb",
"//pkg/sql/isql",
"//pkg/sql/protoreflect",
"//pkg/sql/tests",
"//pkg/storage",
"//pkg/testutils",
"//pkg/testutils/datapathutils",
Expand Down
9 changes: 4 additions & 5 deletions pkg/cli/zip_table_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/sql/tests"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -159,15 +159,14 @@ func executeAllCustomQuerys(

func TestCustomQuery(t *testing.T) {
defer leaktest.AfterTest(t)()
ctx := context.Background()
defer log.Scope(t).Close(t)

params, _ := tests.CreateTestServerParams()
cluster := serverutils.StartNewTestCluster(t, 3 /* numNodes */, base.TestClusterArgs{
ServerArgs: params,
ServerArgs: base.TestServerArgs{},
})
defer cluster.Stopper().Stop(context.Background())
testConn := cluster.ServerConn(0 /* idx */)
sqlDB := sqlutils.MakeSQLRunner(testConn)
defer cluster.Stopper().Stop(ctx)

executeAllCustomQuerys(t, sqlDB, zipInternalTablesPerCluster)
executeAllCustomQuerys(t, sqlDB, zipInternalTablesPerNode)
Expand Down
22 changes: 7 additions & 15 deletions pkg/cli/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/tests"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
Expand Down Expand Up @@ -218,10 +217,9 @@ func TestConcurrentZip(t *testing.T) {
ctx := context.Background()

// Three nodes. We want to see what `zip` thinks when one of the nodes is down.
params, _ := tests.CreateTestServerParams()
params.Insecure = true
tc := testcluster.StartTestCluster(t, 3,
base.TestClusterArgs{ServerArgs: params})
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{
ServerArgs: base.TestServerArgs{Insecure: true},
})
defer tc.Stopper().Stop(ctx)

// Zip it. We fake a CLI test context for this.
Expand Down Expand Up @@ -327,14 +325,11 @@ func TestUnavailableZip(t *testing.T) {
}

// Make a 2-node cluster, with an option to make the first node unavailable.
params, _ := tests.CreateTestServerParams()
params.Insecure = true
tc := testcluster.StartTestCluster(t, 2, base.TestClusterArgs{
ServerArgsPerNode: map[int]base.TestServerArgs{
0: {Insecure: true, Knobs: base.TestingKnobs{Store: knobs}},
1: {Insecure: true},
},
ServerArgs: params,
})
defer tc.Stopper().Stop(context.Background())

Expand Down Expand Up @@ -445,10 +440,9 @@ func TestPartialZip(t *testing.T) {
ctx := context.Background()

// Three nodes. We want to see what `zip` thinks when one of the nodes is down.
params, _ := tests.CreateTestServerParams()
params.Insecure = true
tc := testcluster.StartTestCluster(t, 3,
base.TestClusterArgs{ServerArgs: params})
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{
ServerArgs: base.TestServerArgs{Insecure: true},
})
defer tc.Stopper().Stop(ctx)

// Switch off the second node.
Expand Down Expand Up @@ -538,9 +532,7 @@ func TestZipRetries(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

params, _ := tests.CreateTestServerParams()
params.Insecure = true
s, _, _ := serverutils.StartServer(t, params)
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{Insecure: true})
defer s.Stopper().Stop(context.Background())

dir, cleanupFn := testutils.TempDir(t)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/userfile/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ go_test(
"main_test.go",
],
args = ["-test.timeout=295s"],
embed = [":userfile"],
deps = [
":userfile",
"//pkg/base",
"//pkg/blobs",
"//pkg/ccl",
"//pkg/cloud",
"//pkg/cloud/cloudtestutils",
"//pkg/security/securityassets",
Expand All @@ -45,7 +46,6 @@ go_test(
"//pkg/settings/cluster",
"//pkg/sql/isql",
"//pkg/sql/sem/tree",
"//pkg/sql/tests",
"//pkg/testutils",
"//pkg/testutils/serverutils",
"//pkg/util/leaktest",
Expand Down
25 changes: 12 additions & 13 deletions pkg/cloud/userfile/file_table_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// 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 userfile
package userfile_test

import (
"bytes"
Expand All @@ -21,11 +21,11 @@ import (
"github.com/cockroachdb/cockroach/pkg/blobs"
"github.com/cockroachdb/cockroach/pkg/cloud"
"github.com/cockroachdb/cockroach/pkg/cloud/cloudtestutils"
"github.com/cockroachdb/cockroach/pkg/cloud/userfile"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/isql"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"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/util/leaktest"
Expand All @@ -40,14 +40,13 @@ func TestPutUserFileTable(t *testing.T) {
qualifiedTableName := "defaultdb.public.user_file_table_test"
filename := "path/to/file"

testSettings := cluster.MakeTestingClusterSettings()

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, _, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()
testSettings := s.ClusterSettings()

dest := MakeUserFileStorageURI(qualifiedTableName, filename)
dest := userfile.MakeUserFileStorageURI(qualifiedTableName, filename)

db := s.InternalDB().(isql.DB)
cloudtestutils.CheckExportStore(t, dest, false, username.RootUserName(), db, testSettings)
Expand All @@ -56,7 +55,7 @@ func TestPutUserFileTable(t *testing.T) {
username.RootUserName(), db, testSettings)

t.Run("empty-qualified-table-name", func(t *testing.T) {
dest := MakeUserFileStorageURI("", filename)
dest := userfile.MakeUserFileStorageURI("", filename)

cloudtestutils.CheckExportStore(t, dest, false, username.RootUserName(), db, testSettings)

Expand Down Expand Up @@ -103,11 +102,11 @@ func TestUserScoping(t *testing.T) {
filename := "path/to/file"

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, sqlDB, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

dest := MakeUserFileStorageURI(qualifiedTableName, "")
dest := userfile.MakeUserFileStorageURI(qualifiedTableName, "")
db := s.InternalDB().(isql.DB)

// Create two users and grant them all privileges on defaultdb.
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/userfile/filetable/filetabletest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ go_test(
],
args = ["-test.timeout=295s"],
deps = [
"//pkg/base",
"//pkg/ccl",
"//pkg/cloud/userfile/filetable",
"//pkg/kv",
"//pkg/security/securityassets",
"//pkg/security/securitytest",
"//pkg/security/username",
"//pkg/server",
"//pkg/sql/isql",
"//pkg/sql/tests",
"//pkg/testutils",
"//pkg/testutils/serverutils",
"//pkg/util/ioctx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"sort"
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/cloud/userfile/filetable"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/sql/isql"
"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/util/ioctx"
Expand Down Expand Up @@ -104,9 +104,9 @@ func TestListAndDeleteFiles(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, _, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, _, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

executor := filetable.MakeInternalFileToTableExecutor(
s.InternalDB().(isql.DB),
Expand Down Expand Up @@ -157,9 +157,9 @@ func TestReadWriteFile(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

executor := filetable.MakeInternalFileToTableExecutor(
s.InternalDB().(isql.DB),
Expand Down Expand Up @@ -332,9 +332,9 @@ func TestUserGrants(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

conn, err := sqlDB.Conn(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -412,9 +412,9 @@ func TestDifferentUserDisallowed(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

conn, err := sqlDB.Conn(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -466,9 +466,9 @@ func TestDifferentRoleDisallowed(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

conn, err := sqlDB.Conn(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -525,9 +525,9 @@ func TestDatabaseScope(t *testing.T) {
defer log.Scope(t).Close(t)

ctx := context.Background()
params, _ := tests.CreateTestServerParams()
s, sqlDB, kvDB := serverutils.StartServer(t, params)
defer s.Stopper().Stop(ctx)
srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
s := srv.TenantOrServer()

executor := filetable.MakeInternalFileToTableExecutor(
s.InternalDB().(isql.DB),
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloud/userfile/filetable/filetabletest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"testing"

"github.com/cockroachdb/cockroach/pkg/ccl"
"github.com/cockroachdb/cockroach/pkg/security/securityassets"
"github.com/cockroachdb/cockroach/pkg/security/securitytest"
"github.com/cockroachdb/cockroach/pkg/server"
Expand All @@ -27,5 +28,6 @@ func TestMain(m *testing.M) {
securityassets.SetLoader(securitytest.EmbeddedAssets)
randutil.SeedForTests()
serverutils.InitTestServerFactory(server.TestServerFactory)
defer ccl.TestingEnableEnterprise()()
os.Exit(m.Run())
}
2 changes: 2 additions & 0 deletions pkg/cloud/userfile/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"testing"

"github.com/cockroachdb/cockroach/pkg/ccl"
"github.com/cockroachdb/cockroach/pkg/security/securityassets"
"github.com/cockroachdb/cockroach/pkg/security/securitytest"
"github.com/cockroachdb/cockroach/pkg/server"
Expand All @@ -27,5 +28,6 @@ func TestMain(m *testing.M) {
securityassets.SetLoader(securitytest.EmbeddedAssets)
randutil.SeedForTests()
serverutils.InitTestServerFactory(server.TestServerFactory)
defer ccl.TestingEnableEnterprise()()
os.Exit(m.Run())
}
1 change: 0 additions & 1 deletion pkg/jobs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ go_test(
"//pkg/sql/sem/tree",
"//pkg/sql/sessiondata",
"//pkg/sql/sqlliveness",
"//pkg/sql/tests",
"//pkg/testutils",
"//pkg/testutils/jobutils",
"//pkg/testutils/serverutils",
Expand Down
Loading

0 comments on commit 6035b1a

Please sign in to comment.