From a6e57dd663d6480b7f4e8a2919a28f6667c65ea2 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Tue, 13 Jun 2023 15:05:04 -0700 Subject: [PATCH] backupccl: adjust a test to run for secondary tenant codec too Release note: None --- pkg/ccl/backupccl/BUILD.bazel | 1 - pkg/ccl/backupccl/backup_test.go | 67 +++++++++++++++++++------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/pkg/ccl/backupccl/BUILD.bazel b/pkg/ccl/backupccl/BUILD.bazel index eecec88e833c..42184093478c 100644 --- a/pkg/ccl/backupccl/BUILD.bazel +++ b/pkg/ccl/backupccl/BUILD.bazel @@ -291,7 +291,6 @@ go_test( "//pkg/testutils/datapathutils", "//pkg/testutils/distsqlutils", "//pkg/testutils/jobutils", - "//pkg/testutils/keysutils", "//pkg/testutils/serverutils", "//pkg/testutils/skip", "//pkg/testutils/sqlutils", diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index 5968a404c78c..a394673c5785 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -90,7 +90,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/stats" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/jobutils" - "github.com/cockroachdb/cockroach/pkg/testutils/keysutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/testutils/skip" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" @@ -6177,11 +6176,7 @@ func getMockTableDesc( // methods. func TestPublicIndexTableSpans(t *testing.T) { defer leaktest.AfterTest(t)() - codec := keysutils.TestingSQLCodec - execCfg := &sql.ExecutorConfig{ - Codec: codec, - } - unusedMap := make(map[tableAndIndex]bool) + testCases := []struct { name string tableID descpb.ID @@ -6268,29 +6263,49 @@ func TestPublicIndexTableSpans(t *testing.T) { }, } - for _, test := range testCases { - tableDesc := getMockTableDesc(test.tableID, test.pkIndex, - test.indexes, test.addingIndexes, test.droppingIndexes) - t.Run(fmt.Sprintf("%s:%s", "forEachPublicIndexTableSpan", test.name), func(t *testing.T) { - var spans []roachpb.Span - forEachPublicIndexTableSpan(tableDesc.TableDesc(), unusedMap, codec, func(sp roachpb.Span) { - spans = append(spans, sp) - }) - var unmergedSpans []string - for _, span := range spans { - unmergedSpans = append(unmergedSpans, span.String()) + for _, useSecondaryTenant := range []bool{false, true} { + name, codec := "system", keys.SystemSQLCodec + if useSecondaryTenant { + const tenantID = 42 + name, codec = "secondary", keys.MakeSQLCodec(roachpb.MustMakeTenantID(tenantID)) + for _, tc := range testCases { + for i, sp := range tc.expectedSpans { + tc.expectedSpans[i] = fmt.Sprintf("/Tenant/%d%s", tenantID, sp) + } + for i, sp := range tc.expectedMergedSpans { + tc.expectedMergedSpans[i] = fmt.Sprintf("/Tenant/%d%s", tenantID, sp) + } } - require.Equal(t, test.expectedSpans, unmergedSpans) - }) + } + execCfg := &sql.ExecutorConfig{Codec: codec} + unusedMap := make(map[tableAndIndex]bool) - t.Run(fmt.Sprintf("%s:%s", "spansForAllTableIndexes", test.name), func(t *testing.T) { - mergedSpans, err := spansForAllTableIndexes(execCfg, []catalog.TableDescriptor{tableDesc}, nil /* revs */) - require.NoError(t, err) - var mergedSpanStrings []string - for _, mSpan := range mergedSpans { - mergedSpanStrings = append(mergedSpanStrings, mSpan.String()) + t.Run(name, func(t *testing.T) { + for _, test := range testCases { + tableDesc := getMockTableDesc(test.tableID, test.pkIndex, + test.indexes, test.addingIndexes, test.droppingIndexes) + t.Run(fmt.Sprintf("%s:%s", "forEachPublicIndexTableSpan", test.name), func(t *testing.T) { + var spans []roachpb.Span + forEachPublicIndexTableSpan(tableDesc.TableDesc(), unusedMap, codec, func(sp roachpb.Span) { + spans = append(spans, sp) + }) + var unmergedSpans []string + for _, span := range spans { + unmergedSpans = append(unmergedSpans, span.String()) + } + require.Equal(t, test.expectedSpans, unmergedSpans) + }) + + t.Run(fmt.Sprintf("%s:%s", "spansForAllTableIndexes", test.name), func(t *testing.T) { + mergedSpans, err := spansForAllTableIndexes(execCfg, []catalog.TableDescriptor{tableDesc}, nil /* revs */) + require.NoError(t, err) + var mergedSpanStrings []string + for _, mSpan := range mergedSpans { + mergedSpanStrings = append(mergedSpanStrings, mSpan.String()) + } + require.Equal(t, test.expectedMergedSpans, mergedSpanStrings) + }) } - require.Equal(t, test.expectedMergedSpans, mergedSpanStrings) }) } }