Files
tidb/pkg/lightning/backend/external/codec_test.go
2025-05-08 03:57:43 +00:00

54 lines
1.5 KiB
Go

// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package external
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestRangePropertyCodec(t *testing.T) {
prop := &rangeProperty{
firstKey: []byte("key"),
lastKey: []byte("key2"),
offset: 1,
size: 2,
keys: 3,
}
buf := encodeProp(nil, prop)
prop2 := decodeProp(buf)
require.EqualValues(t, prop, prop2)
p1, p2, p3 := &rangeProperty{}, &rangeProperty{}, &rangeProperty{}
for i, p := range []*rangeProperty{p1, p2, p3} {
p.firstKey = fmt.Appendf(nil, "key%d", i)
p.lastKey = fmt.Appendf(nil, "key%d9", i)
p.offset = uint64(10 * i)
p.size = uint64(20 * i)
p.keys = uint64(30 * i)
}
buf = encodeMultiProps(nil, []*rangeProperty{p1, p2, p3})
props := decodeMultiProps(buf)
require.EqualValues(t, []*rangeProperty{p1, p2, p3}, props)
}
func TestPropertyLengthExceptKeys(t *testing.T) {
zero := &rangeProperty{}
bs := encodeProp(nil, zero)
require.EqualValues(t, propertyLengthExceptKeys, len(bs))
}