github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/privileged_accessor_test.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql_test 12 13 import ( 14 "context" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/keys" 18 "github.com/cockroachdb/cockroach/pkg/kv" 19 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 20 "github.com/cockroachdb/cockroach/pkg/sql/tests" 21 "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" 22 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 23 "github.com/stretchr/testify/assert" 24 "github.com/stretchr/testify/require" 25 ) 26 27 // TestLookupNamespaceID tests the lookup namespace id falls back 28 // onto system.namespace_deprecated. 29 func TestLookupNamespaceIDFallback(t *testing.T) { 30 defer leaktest.AfterTest(t)() 31 32 ctx := context.Background() 33 params, _ := tests.CreateTestServerParams() 34 s, sqlDB, kvDB := serverutils.StartServer(t, params) 35 defer s.Stopper().Stop(ctx) 36 37 err := kvDB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { 38 return txn.Put( 39 ctx, 40 sqlbase.NewDeprecatedTableKey(999, "bob").Key(keys.SystemSQLCodec), 41 9999, 42 ) 43 }) 44 require.NoError(t, err) 45 46 // Assert the row exists in the database. 47 var id int64 48 err = sqlDB.QueryRow( 49 `SELECT crdb_internal.get_namespace_id($1, $2)`, 50 999, 51 "bob", 52 ).Scan(&id) 53 require.NoError(t, err) 54 assert.Equal(t, int64(9999), id) 55 }