mirror of
https://github.com/talent-plan/tinykv.git
synced 2025-01-28 21:30:48 +08:00
5e089a2cd1
Signed-off-by: Connor <zbk602423539@gmail.com> Co-authored-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: linning <linningde25@gmail.com> Co-authored-by: YangKeao <keao.yang@yahoo.com> Co-authored-by: andylokandy <andylokandy@hotmail.com> Co-authored-by: Iosmanthus Teng <myosmanthustree@gmail.com>
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pingcap-incubator/tinykv/proto/pkg/metapb"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRaftstoreErrToPbError(t *testing.T) {
|
|
regionId := uint64(1)
|
|
notLeader := &ErrNotLeader{RegionId: regionId, Leader: nil}
|
|
pbErr := RaftstoreErrToPbError(notLeader)
|
|
require.NotNil(t, pbErr.NotLeader)
|
|
assert.Equal(t, pbErr.NotLeader.RegionId, regionId)
|
|
|
|
regionNotFound := &ErrRegionNotFound{RegionId: regionId}
|
|
pbErr = RaftstoreErrToPbError(regionNotFound)
|
|
require.NotNil(t, pbErr.RegionNotFound)
|
|
assert.Equal(t, pbErr.RegionNotFound.RegionId, regionId)
|
|
|
|
region := &metapb.Region{Id: regionId, StartKey: []byte{0}, EndKey: []byte{1}}
|
|
|
|
keyNotInRegion := &ErrKeyNotInRegion{Key: []byte{2}, Region: region}
|
|
pbErr = RaftstoreErrToPbError(keyNotInRegion)
|
|
require.NotNil(t, pbErr.KeyNotInRegion)
|
|
assert.Equal(t, pbErr.KeyNotInRegion.StartKey, []byte{0})
|
|
assert.Equal(t, pbErr.KeyNotInRegion.EndKey, []byte{1})
|
|
assert.Equal(t, pbErr.KeyNotInRegion.Key, []byte{2})
|
|
|
|
epochNotMatch := &ErrEpochNotMatch{Regions: []*metapb.Region{region}}
|
|
pbErr = RaftstoreErrToPbError(epochNotMatch)
|
|
require.NotNil(t, pbErr.EpochNotMatch)
|
|
assert.Equal(t, pbErr.EpochNotMatch.CurrentRegions, []*metapb.Region{region})
|
|
|
|
staleCommand := &ErrStaleCommand{}
|
|
pbErr = RaftstoreErrToPbError(staleCommand)
|
|
require.NotNil(t, pbErr.StaleCommand)
|
|
|
|
requestStoreId, actualStoreId := uint64(1), uint64(2)
|
|
storeNotMatch := &ErrStoreNotMatch{RequestStoreId: requestStoreId, ActualStoreId: actualStoreId}
|
|
pbErr = RaftstoreErrToPbError(storeNotMatch)
|
|
require.NotNil(t, pbErr.StoreNotMatch)
|
|
assert.Equal(t, pbErr.StoreNotMatch.RequestStoreId, requestStoreId)
|
|
assert.Equal(t, pbErr.StoreNotMatch.ActualStoreId, actualStoreId)
|
|
}
|