github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/config/keys_test.go (about) 1 // Copyright 2015 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 config_test 12 13 import ( 14 "bytes" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/config" 18 "github.com/cockroachdb/cockroach/pkg/keys" 19 "github.com/cockroachdb/cockroach/pkg/roachpb" 20 "github.com/cockroachdb/cockroach/pkg/testutils" 21 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 22 ) 23 24 func TestDecodeObjectID(t *testing.T) { 25 defer leaktest.AfterTest(t)() 26 27 testCases := []struct { 28 key roachpb.RKey 29 keySuffix []byte 30 success bool 31 id uint32 32 }{ 33 // Before the structured span. 34 {roachpb.RKeyMin, nil, false, 0}, 35 36 // Boundaries of structured span. 37 {roachpb.RKeyMax, nil, false, 0}, 38 39 // Valid, even if there are things after the ID. 40 {testutils.MakeKey(keys.SystemSQLCodec.TablePrefix(42), roachpb.RKey("\xff")), []byte{'\xff'}, true, 42}, 41 {roachpb.RKey(keys.SystemSQLCodec.TablePrefix(0)), []byte{}, true, 0}, 42 {roachpb.RKey(keys.SystemSQLCodec.TablePrefix(999)), []byte{}, true, 999}, 43 } 44 45 for tcNum, tc := range testCases { 46 id, keySuffix, success := config.DecodeObjectID(tc.key) 47 if success != tc.success { 48 t.Errorf("#%d: expected success=%t", tcNum, tc.success) 49 continue 50 } 51 if id != tc.id { 52 t.Errorf("#%d: expected id=%d, got %d", tcNum, tc.id, id) 53 } 54 if !bytes.Equal(keySuffix, tc.keySuffix) { 55 t.Errorf("#%d: expected suffix=%q, got %q", tcNum, tc.keySuffix, keySuffix) 56 } 57 } 58 }