MCPcopy
hub / github.com/pingcap/tidb / TestRecordKey

Function TestRecordKey

pkg/tablecodec/tablecodec_test.go:425–450  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

423}
424
425func TestRecordKey(t *testing.T) {
426 tableID := int64(55)
427 tableKey := EncodeRowKeyWithHandle(tableID, kv.IntHandle(math.MaxUint32))
428 tTableID, _, isRecordKey, err := DecodeKeyHead(tableKey)
429 require.NoError(t, err)
430 require.Equal(t, tableID, tTableID)
431 require.True(t, isRecordKey)
432
433 encodedHandle := codec.EncodeInt(nil, math.MaxUint32)
434 rowKey := EncodeRowKey(tableID, encodedHandle)
435 require.Equal(t, []byte(rowKey), []byte(tableKey))
436 tTableID, handle, err := DecodeRecordKey(rowKey)
437 require.NoError(t, err)
438 require.Equal(t, tableID, tTableID)
439 require.Equal(t, int64(math.MaxUint32), handle.IntValue())
440
441 recordPrefix := GenTableRecordPrefix(tableID)
442 rowKey = EncodeRecordKey(recordPrefix, kv.IntHandle(math.MaxUint32))
443 require.Equal(t, []byte(rowKey), []byte(tableKey))
444
445 _, _, err = DecodeRecordKey(nil)
446 require.Error(t, err)
447 _, _, err = DecodeRecordKey([]byte("abcdefghijklmnopqrstuvwxyz"))
448 require.Error(t, err)
449 require.Equal(t, int64(0), DecodeTableID(nil))
450}
451
452func TestPrefix(t *testing.T) {
453 const tableID int64 = 66

Callers

nothing calls this directly

Calls 12

IntHandleTypeAlias · 0.92
EncodeIntFunction · 0.92
EncodeRowKeyWithHandleFunction · 0.85
DecodeKeyHeadFunction · 0.85
EncodeRowKeyFunction · 0.85
DecodeRecordKeyFunction · 0.85
GenTableRecordPrefixFunction · 0.85
EncodeRecordKeyFunction · 0.85
DecodeTableIDFunction · 0.85
EqualMethod · 0.65
IntValueMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected